mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 00:13:21 +01:00
commit
c65ca858cd
650
Cargo.lock
generated
650
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -58,6 +58,7 @@ dirs = "2.0.1"
|
||||
ctrlc = "3.1.3"
|
||||
ptree = "0.2"
|
||||
clipboard = "0.5"
|
||||
reqwest = "0.9"
|
||||
|
||||
[dependencies.pancurses]
|
||||
version = "0.16"
|
||||
|
@ -6,7 +6,7 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn open(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
if args.positional.len() == 0 {
|
||||
return Err(ShellError::string("open requires a filepath"));
|
||||
return Err(ShellError::string("open requires a filepath or url"));
|
||||
}
|
||||
|
||||
let cwd = args.env.lock().unwrap().cwd().to_path_buf();
|
||||
@ -14,15 +14,38 @@ pub fn open(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
|
||||
let contents = match &args.positional[0].item {
|
||||
Value::Primitive(Primitive::String(s)) => {
|
||||
full_path.push(Path::new(&s));
|
||||
match std::fs::read_to_string(&full_path) {
|
||||
Ok(s) => s,
|
||||
Err(_) => {
|
||||
return Err(ShellError::labeled_error(
|
||||
"File cound not be opened",
|
||||
"file not found",
|
||||
args.positional[0].span,
|
||||
));
|
||||
if s.starts_with("http:") || s.starts_with("https:") {
|
||||
let response = reqwest::get(s);
|
||||
match response {
|
||||
Ok(mut r) => match r.text() {
|
||||
Ok(s) => s,
|
||||
Err(_) => {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Web page contents corrupt",
|
||||
"received garbled data",
|
||||
args.positional[0].span,
|
||||
));
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
return Err(ShellError::labeled_error(
|
||||
"URL could not be opened",
|
||||
"url not found",
|
||||
args.positional[0].span,
|
||||
));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
full_path.push(Path::new(&s));
|
||||
match std::fs::read_to_string(&full_path) {
|
||||
Ok(s) => s,
|
||||
Err(_) => {
|
||||
return Err(ShellError::labeled_error(
|
||||
"File cound not be opened",
|
||||
"file not found",
|
||||
args.positional[0].span,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ use crate::prelude::*;
|
||||
use derive_new::new;
|
||||
use language_reporting::{Diagnostic, Label, Severity};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Serialize, Deserialize)]
|
||||
pub enum ShellError {
|
||||
|
@ -12,7 +12,6 @@ use ordered_float::OrderedFloat;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, new)]
|
||||
pub struct OF64 {
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::object::types::Type;
|
||||
use derive_new::new;
|
||||
use serde::{Serialize, Serializer};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
pub enum DescriptorName {
|
||||
|
Loading…
Reference in New Issue
Block a user