Migrate most uses of the Span concept to Tag

Also migrate mv, rm and commands like that to taking a
SyntaxType::Pattern instead of a SyntaxType::Path for their first
argument.
This commit is contained in:
Yehuda Katz
2019-09-10 20:23:22 -07:00
parent f47349c1a0
commit 58b7800172
97 changed files with 1174 additions and 1255 deletions

View File

@ -10,8 +10,7 @@ impl WholeStreamCommand for CD {
}
fn signature(&self) -> Signature {
Signature::build("cd")
.optional("directory", SyntaxType::Path)
Signature::build("cd").optional("directory", SyntaxShape::Path)
}
fn usage(&self) -> &str {

View File

@ -86,7 +86,7 @@ pub(crate) enum ClassifiedCommand {
pub(crate) struct InternalCommand {
pub(crate) command: Arc<Command>,
pub(crate) name_span: Span,
pub(crate) name_tag: Tag,
pub(crate) args: hir::Call,
}
@ -108,7 +108,7 @@ impl InternalCommand {
let result = context.run_command(
self.command,
self.name_span.clone(),
self.name_tag.clone(),
context.source_map.clone(),
self.args,
&source,
@ -133,21 +133,18 @@ impl InternalCommand {
match value {
Tagged {
item: Value::Primitive(Primitive::String(cmd)),
..
tag,
} => {
context.shell_manager.insert_at_current(Box::new(
HelpShell::for_command(
Tagged::from_simple_spanned_item(
Value::string(cmd),
Span::unknown(),
),
&context.registry().clone(),
Value::string(cmd).tagged(tag),
&context.registry(),
)?,
));
}
_ => {
context.shell_manager.insert_at_current(Box::new(
HelpShell::index(&context.registry().clone())?,
HelpShell::index(&context.registry())?,
));
}
}
@ -189,7 +186,7 @@ impl InternalCommand {
pub(crate) struct ExternalCommand {
pub(crate) name: String,
pub(crate) name_span: Span,
pub(crate) name_tag: Tag,
pub(crate) args: Vec<Tagged<String>>,
}
@ -208,7 +205,7 @@ impl ExternalCommand {
) -> Result<ClassifiedInputStream, ShellError> {
let stdin = input.stdin;
let inputs: Vec<Tagged<Value>> = input.objects.into_vec().await;
let name_span = self.name_span.clone();
let name_tag = self.name_tag.clone();
trace!(target: "nu::run::external", "-> {}", self.name);
trace!(target: "nu::run::external", "inputs = {:?}", inputs);
@ -227,17 +224,17 @@ impl ExternalCommand {
for i in &inputs {
if i.as_string().is_err() {
let mut span = None;
let mut tag = None;
for arg in &self.args {
if arg.item.contains("$it") {
span = Some(arg.span());
tag = Some(arg.tag());
}
}
if let Some(span) = span {
if let Some(tag) = tag {
return Err(ShellError::labeled_error(
"External $it needs string data",
"given row instead of string data",
span,
tag,
));
} else {
return Err(ShellError::string("Error: $it needs string data"));
@ -314,9 +311,7 @@ impl ExternalCommand {
let stdout = popen.stdout.take().unwrap();
let file = futures::io::AllowStdIo::new(stdout);
let stream = Framed::new(file, LinesCodec {});
let stream = stream.map(move |line| {
Tagged::from_simple_spanned_item(Value::string(line.unwrap()), name_span)
});
let stream = stream.map(move |line| Value::string(line.unwrap()).tagged(name_tag));
Ok(ClassifiedInputStream::from_input_stream(
stream.boxed() as BoxStream<'static, Tagged<Value>>
))

View File

@ -51,7 +51,7 @@ pub mod clipboard {
Ok(OutputStream::from(stream))
}
async fn inner_clip(input: Vec<Tagged<Value>>, name: Span) -> OutputStream {
async fn inner_clip(input: Vec<Tagged<Value>>, name: Tag) -> OutputStream {
let mut clip_context: ClipboardContext = ClipboardProvider::new().unwrap();
let mut new_copy_data = String::new();

View File

@ -18,7 +18,7 @@ pub struct UnevaluatedCallInfo {
pub args: hir::Call,
pub source: Text,
pub source_map: SourceMap,
pub name_span: Span,
pub name_tag: Tag,
}
impl ToDebug for UnevaluatedCallInfo {
@ -38,7 +38,7 @@ impl UnevaluatedCallInfo {
Ok(CallInfo {
args,
source_map: self.source_map,
name_span: self.name_span,
name_tag: self.name_tag,
})
}
@ -74,7 +74,7 @@ impl UnevaluatedCallInfo {
pub struct CallInfo {
pub args: registry::EvaluatedArgs,
pub source_map: SourceMap,
pub name_span: Span,
pub name_tag: Tag,
}
impl CallInfo {
@ -89,7 +89,7 @@ impl CallInfo {
args: T::deserialize(&mut deserializer)?,
context: RunnablePerItemContext {
shell_manager: shell_manager.clone(),
name: self.name_span,
name: self.name_tag,
},
callback,
})
@ -158,7 +158,7 @@ impl CommandArgs {
let host = self.host.clone();
let args = self.evaluate_once(registry)?;
let (input, args) = args.split();
let name_span = args.call_info.name_span;
let name_tag = args.call_info.name_tag;
let mut deserializer = ConfigDeserializer::from_call_info(args.call_info);
Ok(RunnableArgs {
@ -167,7 +167,7 @@ impl CommandArgs {
input,
commands: registry.clone(),
shell_manager,
name: name_span,
name: name_tag,
source_map,
host,
},
@ -191,7 +191,7 @@ impl CommandArgs {
let host = self.host.clone();
let args = self.evaluate_once(registry)?;
let (input, args) = args.split();
let name_span = args.call_info.name_span;
let name_tag = args.call_info.name_tag;
let mut deserializer = ConfigDeserializer::from_call_info(args.call_info);
Ok(RunnableRawArgs {
@ -200,7 +200,7 @@ impl CommandArgs {
input,
commands: registry.clone(),
shell_manager,
name: name_span,
name: name_tag,
source_map,
host,
},
@ -212,7 +212,7 @@ impl CommandArgs {
pub struct RunnablePerItemContext {
pub shell_manager: ShellManager,
pub name: Span,
pub name: Tag,
}
impl RunnablePerItemContext {
@ -227,7 +227,7 @@ pub struct RunnableContext {
pub host: Arc<Mutex<dyn Host>>,
pub commands: CommandRegistry,
pub source_map: SourceMap,
pub name: Span,
pub name: Tag,
}
impl RunnableContext {
@ -311,8 +311,8 @@ impl EvaluatedWholeStreamCommandArgs {
}
}
pub fn name_span(&self) -> Span {
self.args.call_info.name_span
pub fn name_tag(&self) -> Tag {
self.args.call_info.name_tag
}
pub fn parts(self) -> (InputStream, registry::EvaluatedArgs) {
@ -471,12 +471,6 @@ impl ReturnSuccess {
pub fn action(input: CommandAction) -> ReturnValue {
Ok(ReturnSuccess::Action(input))
}
pub fn spanned_value(input: Value, span: Span) -> ReturnValue {
Ok(ReturnSuccess::Value(Tagged::from_simple_spanned_item(
input, span,
)))
}
}
pub trait WholeStreamCommand: Send + Sync {

View File

@ -1,7 +1,7 @@
use crate::commands::WholeStreamCommand;
use crate::data::{config, Value};
use crate::errors::ShellError;
use crate::parser::hir::SyntaxType;
use crate::parser::hir::SyntaxShape;
use crate::parser::registry::{self};
use crate::prelude::*;
use std::iter::FromIterator;
@ -26,10 +26,10 @@ impl WholeStreamCommand for Config {
fn signature(&self) -> Signature {
Signature::build("config")
.named("load", SyntaxType::Path)
.named("set", SyntaxType::Any)
.named("get", SyntaxType::Any)
.named("remove", SyntaxType::Any)
.named("load", SyntaxShape::Path)
.named("set", SyntaxShape::Any)
.named("get", SyntaxShape::Any)
.named("remove", SyntaxShape::Any)
.switch("clear")
.switch("path")
}
@ -96,41 +96,21 @@ pub fn config(
config::write(&result, &configuration)?;
return Ok(stream![Tagged::from_simple_spanned_item(
Value::Row(result.into()),
value.span()
)]
.from_input_stream());
return Ok(stream![Value::Row(result.into()).tagged(value.tag())].from_input_stream());
}
if let Tagged {
item: true,
tag: Tag { span, .. },
} = clear
{
if let Tagged { item: true, tag } = clear {
result.clear();
config::write(&result, &configuration)?;
return Ok(stream![Tagged::from_simple_spanned_item(
Value::Row(result.into()),
span
)]
.from_input_stream());
return Ok(stream![Value::Row(result.into()).tagged(tag)].from_input_stream());
}
if let Tagged {
item: true,
tag: Tag { span, .. },
} = path
{
if let Tagged { item: true, tag } = path {
let path = config::default_path_for(&configuration)?;
return Ok(stream![Tagged::from_simple_spanned_item(
Value::Primitive(Primitive::Path(path)),
span
)]
.from_input_stream());
return Ok(stream![Value::Primitive(Primitive::Path(path)).tagged(tag)].from_input_stream());
}
if let Some(v) = remove {
@ -146,9 +126,9 @@ pub fn config(
)));
}
let obj = VecDeque::from_iter(vec![Value::Row(result.into()).simple_spanned(v.span())]);
let obj = VecDeque::from_iter(vec![Value::Row(result.into()).tagged(v.tag())]);
return Ok(obj.from_input_stream());
}
return Ok(vec![Value::Row(result.into()).simple_spanned(name)].into());
return Ok(vec![Value::Row(result.into()).tagged(name)].into());
}

View File

@ -1,6 +1,6 @@
use crate::commands::command::RunnablePerItemContext;
use crate::errors::ShellError;
use crate::parser::hir::SyntaxType;
use crate::parser::hir::SyntaxShape;
use crate::parser::registry::{CommandRegistry, Signature};
use crate::prelude::*;
use std::path::PathBuf;
@ -21,9 +21,9 @@ impl PerItemCommand for Cpy {
fn signature(&self) -> Signature {
Signature::build("cp")
.required("src", SyntaxType::Pattern)
.required("dst", SyntaxType::Path)
.named("file", SyntaxType::Any)
.required("src", SyntaxShape::Pattern)
.required("dst", SyntaxShape::Path)
.named("file", SyntaxShape::Any)
.switch("recursive")
}

View File

@ -1,5 +1,5 @@
use crate::errors::ShellError;
use crate::data::{Dictionary, Value};
use crate::errors::ShellError;
use crate::prelude::*;
use chrono::{DateTime, Local, Utc};
@ -33,58 +33,40 @@ impl WholeStreamCommand for Date {
}
}
pub fn date_to_value<T: TimeZone>(dt: DateTime<T>, span: Span) -> Tagged<Value>
pub fn date_to_value<T: TimeZone>(dt: DateTime<T>, tag: Tag) -> Tagged<Value>
where
T::Offset: Display,
{
let mut indexmap = IndexMap::new();
indexmap.insert(
"year".to_string(),
Tagged::from_simple_spanned_item(Value::int(dt.year()), span),
);
indexmap.insert(
"month".to_string(),
Tagged::from_simple_spanned_item(Value::int(dt.month()), span),
);
indexmap.insert(
"day".to_string(),
Tagged::from_simple_spanned_item(Value::int(dt.day()), span),
);
indexmap.insert(
"hour".to_string(),
Tagged::from_simple_spanned_item(Value::int(dt.hour()), span),
);
indexmap.insert(
"minute".to_string(),
Tagged::from_simple_spanned_item(Value::int(dt.minute()), span),
);
indexmap.insert(
"second".to_string(),
Tagged::from_simple_spanned_item(Value::int(dt.second()), span),
);
indexmap.insert("year".to_string(), Value::int(dt.year()).tagged(tag));
indexmap.insert("month".to_string(), Value::int(dt.month()).tagged(tag));
indexmap.insert("day".to_string(), Value::int(dt.day()).tagged(tag));
indexmap.insert("hour".to_string(), Value::int(dt.hour()).tagged(tag));
indexmap.insert("minute".to_string(), Value::int(dt.minute()).tagged(tag));
indexmap.insert("second".to_string(), Value::int(dt.second()).tagged(tag));
let tz = dt.offset();
indexmap.insert(
"timezone".to_string(),
Tagged::from_simple_spanned_item(Value::string(format!("{}", tz)), span),
Value::string(format!("{}", tz)).tagged(tag),
);
Tagged::from_simple_spanned_item(Value::Row(Dictionary::from(indexmap)), span)
Value::Row(Dictionary::from(indexmap)).tagged(tag)
}
pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let mut date_out = VecDeque::new();
let span = args.call_info.name_span;
let tag = args.call_info.name_tag;
let value = if args.has("utc") {
let utc: DateTime<Utc> = Utc::now();
date_to_value(utc, span)
date_to_value(utc, tag)
} else {
let local: DateTime<Local> = Local::now();
date_to_value(local, span)
date_to_value(local, tag)
};
date_out.push_back(value);

View File

@ -12,7 +12,7 @@ impl PerItemCommand for Echo {
}
fn signature(&self) -> Signature {
Signature::build("echo").rest(SyntaxType::Any)
Signature::build("echo").rest(SyntaxShape::Any)
}
fn usage(&self) -> &str {
@ -35,7 +35,7 @@ fn run(
_registry: &CommandRegistry,
_raw_args: &RawCommandArgs,
) -> Result<OutputStream, ShellError> {
let name = call_info.name_span;
let name = call_info.name_tag;
let mut output = String::new();
@ -57,7 +57,7 @@ fn run(
return Err(ShellError::labeled_error(
"Expect a string from pipeline",
"not a string-compatible value",
i.span(),
i.tag(),
));
}
}
@ -65,7 +65,7 @@ fn run(
}
let stream = VecDeque::from(vec![Ok(ReturnSuccess::Value(
Value::string(output).simple_spanned(name),
Value::string(output).tagged(name),
))]);
Ok(stream.to_output_stream())

View File

@ -14,7 +14,7 @@ impl PerItemCommand for Enter {
}
fn signature(&self) -> registry::Signature {
Signature::build("enter").required("location", SyntaxType::Block)
Signature::build("enter").required("location", SyntaxShape::Block)
}
fn usage(&self) -> &str {
@ -70,7 +70,7 @@ impl PerItemCommand for Enter {
crate::commands::open::fetch(
&full_path,
&location_clone,
Span::unknown(),
Tag::unknown(),
)
.await.unwrap();
@ -103,7 +103,7 @@ impl PerItemCommand for Enter {
},
source: raw_args.call_info.source,
source_map: raw_args.call_info.source_map,
name_span: raw_args.call_info.name_span,
name_tag: raw_args.call_info.name_tag,
},
};
let mut result = converter.run(

View File

@ -2,14 +2,13 @@ use crate::commands::UnevaluatedCallInfo;
use crate::context::SpanSource;
use crate::data::Value;
use crate::errors::ShellError;
use crate::parser::hir::SyntaxType;
use crate::parser::hir::SyntaxShape;
use crate::parser::registry::Signature;
use crate::prelude::*;
use mime::Mime;
use std::path::PathBuf;
use std::str::FromStr;
use surf::mime;
use uuid::Uuid;
pub struct Fetch;
impl PerItemCommand for Fetch {
@ -19,7 +18,7 @@ impl PerItemCommand for Fetch {
fn signature(&self) -> Signature {
Signature::build(self.name())
.required("path", SyntaxType::Path)
.required("path", SyntaxShape::Path)
.switch("raw")
}
@ -52,14 +51,14 @@ fn run(
};
let path_buf = path.as_path()?;
let path_str = path_buf.display().to_string();
let path_span = path.span();
let path_tag = path.tag();
let has_raw = call_info.args.has("raw");
let registry = registry.clone();
let raw_args = raw_args.clone();
let stream = async_stream_block! {
let result = fetch(&path_str, path_span).await;
let result = fetch(&path_str, path_tag).await;
if let Err(e) = result {
yield Err(e);
@ -99,7 +98,7 @@ fn run(
},
source: raw_args.call_info.source,
source_map: raw_args.call_info.source_map,
name_span: raw_args.call_info.name_span,
name_tag: raw_args.call_info.name_tag,
}
};
let mut result = converter.run(new_args.with_input(vec![tagged_contents]), &registry);
@ -130,13 +129,13 @@ fn run(
pub async fn fetch(
location: &str,
span: Span,
tag: Tag,
) -> Result<(Option<String>, Value, Tag, SpanSource), ShellError> {
if let Err(_) = url::Url::parse(location) {
return Err(ShellError::labeled_error(
"Incomplete or incorrect url",
"expected a full url",
span,
tag,
));
}
@ -152,13 +151,10 @@ pub async fn fetch(
ShellError::labeled_error(
"Could not load text from remote url",
"could not load",
span,
tag,
)
})?),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
)),
(mime::APPLICATION, mime::JSON) => Ok((
@ -167,13 +163,10 @@ pub async fn fetch(
ShellError::labeled_error(
"Could not load text from remote url",
"could not load",
span,
tag,
)
})?),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
)),
(mime::APPLICATION, mime::OCTET_STREAM) => {
@ -181,16 +174,13 @@ pub async fn fetch(
ShellError::labeled_error(
"Could not load binary file",
"could not load",
span,
tag,
)
})?;
Ok((
None,
Value::Binary(buf),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
))
}
@ -200,13 +190,10 @@ pub async fn fetch(
ShellError::labeled_error(
"Could not load svg from remote url",
"could not load",
span,
tag,
)
})?),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
)),
(mime::IMAGE, image_ty) => {
@ -214,16 +201,13 @@ pub async fn fetch(
ShellError::labeled_error(
"Could not load image file",
"could not load",
span,
tag,
)
})?;
Ok((
Some(image_ty.to_string()),
Value::Binary(buf),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
))
}
@ -233,13 +217,10 @@ pub async fn fetch(
ShellError::labeled_error(
"Could not load text from remote url",
"could not load",
span,
tag,
)
})?),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
)),
(mime::TEXT, mime::PLAIN) => {
@ -260,23 +241,17 @@ pub async fn fetch(
ShellError::labeled_error(
"Could not load text from remote url",
"could not load",
span,
tag,
)
})?),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
))
}
(ty, sub_ty) => Ok((
None,
Value::string(format!("Not yet supported MIME type: {} {}", ty, sub_ty)),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
)),
}
@ -284,10 +259,7 @@ pub async fn fetch(
None => Ok((
None,
Value::string(format!("No content type found")),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
)),
},
@ -295,7 +267,7 @@ pub async fn fetch(
return Err(ShellError::labeled_error(
"URL could not be opened",
"url not found",
span,
tag,
));
}
}

View File

@ -17,7 +17,7 @@ impl WholeStreamCommand for First {
fn signature(&self) -> Signature {
Signature::build("first")
.required("amount", SyntaxType::Literal)
.required("amount", SyntaxShape::Literal)
}
fn usage(&self) -> &str {

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ExpectedRange;
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::errors::ExpectedRange;
use crate::prelude::*;
use bson::{decode_document, spec::BinarySubtype, Bson};
use std::str::FromStr;
@ -198,7 +198,7 @@ pub fn from_bson_bytes_to_value(
fn from_bson(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let span = args.name_span();
let tag = args.name_tag();
let input = args.input;
let stream = async_stream_block! {
@ -208,24 +208,24 @@ fn from_bson(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStre
let value_tag = value.tag();
match value.item {
Value::Binary(vb) =>
match from_bson_bytes_to_value(vb, span) {
match from_bson_bytes_to_value(vb, tag) {
Ok(x) => yield ReturnSuccess::value(x),
Err(_) => {
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as BSON",
"input cannot be parsed as BSON",
span,
tag,
"value originates from here",
value_tag.span,
value_tag,
))
}
}
_ => yield Err(ShellError::labeled_error_with_secondary(
"Expected a string from pipeline",
"requires string input",
span,
tag,
"value originates from here",
value_tag.span,
value_tag,
)),
}

View File

@ -86,7 +86,7 @@ fn from_csv(
}: FromCSVArgs,
RunnableContext { input, name, .. }: RunnableContext,
) -> Result<OutputStream, ShellError> {
let name_span = name;
let name_tag = name;
let stream = async_stream_block! {
let values: Vec<Tagged<Value>> = input.values.collect().await;
@ -105,15 +105,15 @@ fn from_csv(
_ => yield Err(ShellError::labeled_error_with_secondary(
"Expected a string from pipeline",
"requires string input",
name_span,
name_tag,
"value originates from here",
value_tag.span,
value_tag,
)),
}
}
match from_csv_string_to_value(concat_string, skip_headers, name_span) {
match from_csv_string_to_value(concat_string, skip_headers, name_tag) {
Ok(x) => match x {
Tagged { item: Value::Table(list), .. } => {
for l in list {
@ -126,9 +126,9 @@ fn from_csv(
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as CSV",
"input cannot be parsed as CSV",
name_span,
name_tag,
"value originates from here",
last_tag.span,
last_tag,
))
} ,
}

View File

@ -64,7 +64,7 @@ pub fn from_ini_string_to_value(
fn from_ini(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let span = args.name_span();
let tag = args.name_tag();
let input = args.input;
let stream = async_stream_block! {
@ -84,15 +84,15 @@ fn from_ini(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
_ => yield Err(ShellError::labeled_error_with_secondary(
"Expected a string from pipeline",
"requires string input",
span,
tag,
"value originates from here",
value_tag.span,
value_tag,
)),
}
}
match from_ini_string_to_value(concat_string, span) {
match from_ini_string_to_value(concat_string, tag) {
Ok(x) => match x {
Tagged { item: Value::Table(list), .. } => {
for l in list {
@ -105,9 +105,9 @@ fn from_ini(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as INI",
"input cannot be parsed as INI",
span,
tag,
"value originates from here",
last_tag.span,
last_tag,
))
} ,
}

View File

@ -72,7 +72,7 @@ fn from_json(
FromJSONArgs { objects }: FromJSONArgs,
RunnableContext { input, name, .. }: RunnableContext,
) -> Result<OutputStream, ShellError> {
let name_span = name;
let name_tag = name;
let stream = async_stream_block! {
let values: Vec<Tagged<Value>> = input.values.collect().await;
@ -91,9 +91,9 @@ fn from_json(
_ => yield Err(ShellError::labeled_error_with_secondary(
"Expected a string from pipeline",
"requires string input",
name_span,
name_tag,
"value originates from here",
value_tag.span,
value_tag,
)),
}
@ -106,7 +106,7 @@ fn from_json(
continue;
}
match from_json_string_to_value(json_str.to_string(), name_span) {
match from_json_string_to_value(json_str.to_string(), name_tag) {
Ok(x) =>
yield ReturnSuccess::value(x),
Err(_) => {
@ -114,15 +114,15 @@ fn from_json(
yield Err(ShellError::labeled_error_with_secondary(
"Could nnot parse as JSON",
"input cannot be parsed as JSON",
name_span,
name_tag,
"value originates from here",
last_tag.span))
last_tag))
}
}
}
}
} else {
match from_json_string_to_value(concat_string, name_span) {
match from_json_string_to_value(concat_string, name_tag) {
Ok(x) =>
match x {
Tagged { item: Value::Table(list), .. } => {
@ -137,9 +137,9 @@ fn from_json(
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as JSON",
"input cannot be parsed as JSON",
name_span,
name_tag,
"value originates from here",
last_tag.span))
last_tag))
}
}
}

View File

@ -128,7 +128,7 @@ pub fn from_sqlite_bytes_to_value(
fn from_sqlite(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let span = args.name_span();
let tag = args.name_tag();
let input = args.input;
let stream = async_stream_block! {
@ -138,7 +138,7 @@ fn from_sqlite(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputSt
let value_tag = value.tag();
match value.item {
Value::Binary(vb) =>
match from_sqlite_bytes_to_value(vb, span) {
match from_sqlite_bytes_to_value(vb, tag) {
Ok(x) => match x {
Tagged { item: Value::Table(list), .. } => {
for l in list {
@ -151,18 +151,18 @@ fn from_sqlite(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputSt
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as SQLite",
"input cannot be parsed as SQLite",
span,
tag,
"value originates from here",
value_tag.span,
value_tag,
))
}
}
_ => yield Err(ShellError::labeled_error_with_secondary(
"Expected a string from pipeline",
"requires string input",
span,
tag,
"value originates from here",
value_tag.span,
value_tag,
)),
}

View File

@ -68,7 +68,7 @@ pub fn from_toml(
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let span = args.name_span();
let tag = args.name_tag();
let input = args.input;
let stream = async_stream_block! {
@ -88,15 +88,15 @@ pub fn from_toml(
_ => yield Err(ShellError::labeled_error_with_secondary(
"Expected a string from pipeline",
"requires string input",
span,
tag,
"value originates from here",
value_tag.span,
value_tag,
)),
}
}
match from_toml_string_to_value(concat_string, span) {
match from_toml_string_to_value(concat_string, tag) {
Ok(x) => match x {
Tagged { item: Value::Table(list), .. } => {
for l in list {
@ -109,9 +109,9 @@ pub fn from_toml(
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as TOML",
"input cannot be parsed as TOML",
span,
tag,
"value originates from here",
last_tag.span,
last_tag,
))
} ,
}

View File

@ -87,7 +87,7 @@ fn from_tsv(
}: FromTSVArgs,
RunnableContext { input, name, .. }: RunnableContext,
) -> Result<OutputStream, ShellError> {
let name_span = name;
let name_tag = name;
let stream = async_stream_block! {
let values: Vec<Tagged<Value>> = input.values.collect().await;
@ -106,15 +106,15 @@ fn from_tsv(
_ => yield Err(ShellError::labeled_error_with_secondary(
"Expected a string from pipeline",
"requires string input",
name_span,
name_tag,
"value originates from here",
value_tag.span,
value_tag,
)),
}
}
match from_tsv_string_to_value(concat_string, skip_headers, name_span) {
match from_tsv_string_to_value(concat_string, skip_headers, name_tag) {
Ok(x) => match x {
Tagged { item: Value::Table(list), .. } => {
for l in list {
@ -127,9 +127,9 @@ fn from_tsv(
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as TSV",
"input cannot be parsed as TSV",
name_span,
name_tag,
"value originates from here",
last_tag.span,
last_tag,
))
} ,
}

View File

@ -83,7 +83,7 @@ pub fn from_xml_string_to_value(
fn from_xml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let span = args.name_span();
let tag = args.name_tag();
let input = args.input;
let stream = async_stream_block! {
@ -103,15 +103,15 @@ fn from_xml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
_ => yield Err(ShellError::labeled_error_with_secondary(
"Expected a string from pipeline",
"requires string input",
span,
tag,
"value originates from here",
value_tag.span,
value_tag,
)),
}
}
match from_xml_string_to_value(concat_string, span) {
match from_xml_string_to_value(concat_string, tag) {
Ok(x) => match x {
Tagged { item: Value::Table(list), .. } => {
for l in list {
@ -124,9 +124,9 @@ fn from_xml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as XML",
"input cannot be parsed as XML",
span,
tag,
"value originates from here",
last_tag.span,
last_tag,
))
} ,
}

View File

@ -97,7 +97,7 @@ pub fn from_yaml_string_to_value(
fn from_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let span = args.name_span();
let tag = args.name_tag();
let input = args.input;
let stream = async_stream_block! {
@ -117,15 +117,15 @@ fn from_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStre
_ => yield Err(ShellError::labeled_error_with_secondary(
"Expected a string from pipeline",
"requires string input",
span,
tag,
"value originates from here",
value_tag.span,
value_tag,
)),
}
}
match from_yaml_string_to_value(concat_string, span) {
match from_yaml_string_to_value(concat_string, tag) {
Ok(x) => match x {
Tagged { item: Value::Table(list), .. } => {
for l in list {
@ -138,9 +138,9 @@ fn from_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStre
yield Err(ShellError::labeled_error_with_secondary(
"Could not parse as YAML",
"input cannot be parsed as YAML",
span,
tag,
"value originates from here",
last_tag.span,
last_tag,
))
} ,
}

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::data::Value;
use crate::errors::ShellError;
use crate::prelude::*;
pub struct Get;
@ -16,7 +16,7 @@ impl WholeStreamCommand for Get {
}
fn signature(&self) -> Signature {
Signature::build("get").rest(SyntaxType::Member)
Signature::build("get").rest(SyntaxShape::Member)
}
fn usage(&self) -> &str {
@ -47,7 +47,7 @@ fn get_member(path: &Tagged<String>, obj: &Tagged<Value>) -> Result<Tagged<Value
return Err(ShellError::labeled_error(
"Unknown column",
"table missing column",
path.span(),
path.tag(),
));
}
}

View File

@ -1,7 +1,7 @@
use crate::commands::command::CommandAction;
use crate::commands::PerItemCommand;
use crate::errors::ShellError;
use crate::data::{command_dict, TaggedDictBuilder};
use crate::errors::ShellError;
use crate::parser::registry;
use crate::prelude::*;
@ -13,7 +13,7 @@ impl PerItemCommand for Help {
}
fn signature(&self) -> registry::Signature {
Signature::build("help").rest(SyntaxType::Any)
Signature::build("help").rest(SyntaxShape::Any)
}
fn usage(&self) -> &str {
@ -27,11 +27,11 @@ impl PerItemCommand for Help {
_raw_args: &RawCommandArgs,
_input: Tagged<Value>,
) -> Result<OutputStream, ShellError> {
let span = call_info.name_span;
let tag = call_info.name_tag;
if call_info.args.len() == 0 {
return Ok(vec![Ok(ReturnSuccess::Action(CommandAction::EnterHelpShell(
Tagged::from_simple_spanned_item(Value::nothing(), span),
Value::nothing().tagged(tag),
)))]
.into());
}

View File

@ -16,7 +16,7 @@ impl WholeStreamCommand for Last {
}
fn signature(&self) -> Signature {
Signature::build("last").required("amount", SyntaxType::Number)
Signature::build("last").required("amount", SyntaxShape::Number)
}
fn usage(&self) -> &str {

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::data::{Primitive, Value};
use crate::errors::ShellError;
use crate::prelude::*;
use log::trace;
@ -32,7 +32,7 @@ impl WholeStreamCommand for Lines {
fn lines(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let span = args.name_span();
let tag = args.name_tag();
let input = args.input;
let input: InputStream = trace_stream!(target: "nu::trace_stream::lines", "input" = input);
@ -58,9 +58,9 @@ fn lines(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream,
result.push_back(Err(ShellError::labeled_error_with_secondary(
"Expected a string from pipeline",
"requires string input",
span,
tag,
"value originates from here",
v.span(),
v.tag(),
)));
result
}

View File

@ -1,16 +1,22 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::prelude::*;
use std::path::PathBuf;
pub struct LS;
#[derive(Deserialize)]
pub struct LsArgs {
path: Option<Tagged<PathBuf>>,
}
impl WholeStreamCommand for LS {
fn name(&self) -> &str {
"ls"
}
fn signature(&self) -> Signature {
Signature::build("ls").optional("path", SyntaxType::Pattern)
Signature::build("ls").optional("path", SyntaxShape::Pattern)
}
fn usage(&self) -> &str {
@ -22,12 +28,11 @@ impl WholeStreamCommand for LS {
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
ls(args, registry)
args.process(registry, ls)?.run()
// ls(args, registry)
}
}
fn ls(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let shell_manager = args.shell_manager.clone();
let args = args.evaluate_once(registry)?;
shell_manager.ls(args)
fn ls(LsArgs { path }: LsArgs, context: RunnableContext) -> Result<OutputStream, ShellError> {
context.shell_manager.ls(path, context.name)
}

View File

@ -17,7 +17,7 @@ impl PerItemCommand for Mkdir {
}
fn signature(&self) -> Signature {
Signature::build("mkdir").rest(SyntaxType::Path)
Signature::build("mkdir").rest(SyntaxShape::Path)
}
fn usage(&self) -> &str {

View File

@ -1,6 +1,6 @@
use crate::commands::command::RunnablePerItemContext;
use crate::errors::ShellError;
use crate::parser::hir::SyntaxType;
use crate::parser::hir::SyntaxShape;
use crate::parser::registry::{CommandRegistry, Signature};
use crate::prelude::*;
use std::path::PathBuf;
@ -20,9 +20,9 @@ impl PerItemCommand for Move {
fn signature(&self) -> Signature {
Signature::build("mv")
.required("source", SyntaxType::Path)
.required("destination", SyntaxType::Path)
.named("file", SyntaxType::Any)
.required("source", SyntaxShape::Pattern)
.required("destination", SyntaxShape::Path)
.named("file", SyntaxShape::Any)
}
fn usage(&self) -> &str {

View File

@ -16,7 +16,7 @@ impl WholeStreamCommand for Nth {
}
fn signature(&self) -> Signature {
Signature::build("nth").required("amount", SyntaxType::Any)
Signature::build("nth").required("amount", SyntaxShape::Any)
}
fn usage(&self) -> &str {

View File

@ -2,11 +2,10 @@ use crate::commands::UnevaluatedCallInfo;
use crate::context::SpanSource;
use crate::data::Value;
use crate::errors::ShellError;
use crate::parser::hir::SyntaxType;
use crate::parser::hir::SyntaxShape;
use crate::parser::registry::Signature;
use crate::prelude::*;
use std::path::{Path, PathBuf};
use uuid::Uuid;
pub struct Open;
impl PerItemCommand for Open {
@ -16,7 +15,7 @@ impl PerItemCommand for Open {
fn signature(&self) -> Signature {
Signature::build(self.name())
.required("path", SyntaxType::Path)
.required("path", SyntaxShape::Path)
.switch("raw")
}
@ -53,7 +52,7 @@ fn run(
};
let path_buf = path.as_path()?;
let path_str = path_buf.display().to_string();
let path_span = path.span();
let path_span = path.tag();
let has_raw = call_info.args.has("raw");
let registry = registry.clone();
let raw_args = raw_args.clone();
@ -100,7 +99,7 @@ fn run(
},
source: raw_args.call_info.source,
source_map: raw_args.call_info.source_map,
name_span: raw_args.call_info.name_span,
name_tag: raw_args.call_info.name_tag,
}
};
let mut result = converter.run(new_args.with_input(vec![tagged_contents]), &registry);
@ -132,7 +131,7 @@ fn run(
pub async fn fetch(
cwd: &PathBuf,
location: &str,
span: Span,
tag: Tag,
) -> Result<(Option<String>, Value, Tag, SpanSource), ShellError> {
let mut cwd = cwd.clone();
@ -144,10 +143,7 @@ pub async fn fetch(
cwd.extension()
.map(|name| name.to_string_lossy().to_string()),
Value::string(s),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::File(cwd.to_string_lossy().to_string()),
)),
Err(_) => {
@ -163,19 +159,13 @@ pub async fn fetch(
cwd.extension()
.map(|name| name.to_string_lossy().to_string()),
Value::string(s),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::File(cwd.to_string_lossy().to_string()),
)),
Err(_) => Ok((
None,
Value::Binary(bytes),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::File(cwd.to_string_lossy().to_string()),
)),
}
@ -183,10 +173,7 @@ pub async fn fetch(
Ok((
None,
Value::Binary(bytes),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::File(cwd.to_string_lossy().to_string()),
))
}
@ -201,19 +188,13 @@ pub async fn fetch(
cwd.extension()
.map(|name| name.to_string_lossy().to_string()),
Value::string(s),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::File(cwd.to_string_lossy().to_string()),
)),
Err(_) => Ok((
None,
Value::Binary(bytes),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::File(cwd.to_string_lossy().to_string()),
)),
}
@ -221,10 +202,7 @@ pub async fn fetch(
Ok((
None,
Value::Binary(bytes),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::File(cwd.to_string_lossy().to_string()),
))
}
@ -232,10 +210,7 @@ pub async fn fetch(
_ => Ok((
None,
Value::Binary(bytes),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::File(cwd.to_string_lossy().to_string()),
)),
}
@ -245,7 +220,7 @@ pub async fn fetch(
return Err(ShellError::labeled_error(
"File could not be opened",
"file not found",
span,
tag,
));
}
}
@ -253,7 +228,7 @@ pub async fn fetch(
return Err(ShellError::labeled_error(
"File could not be opened",
"file not found",
span,
tag,
));
}
}

View File

@ -17,7 +17,7 @@ impl WholeStreamCommand for Pick {
}
fn signature(&self) -> Signature {
Signature::build("pick").rest(SyntaxType::Any)
Signature::build("pick").rest(SyntaxShape::Any)
}
fn usage(&self) -> &str {

View File

@ -1,8 +1,8 @@
use crate::commands::UnevaluatedCallInfo;
use crate::context::SpanSource;
use crate::errors::ShellError;
use crate::data::Value;
use crate::parser::hir::SyntaxType;
use crate::errors::ShellError;
use crate::parser::hir::SyntaxShape;
use crate::parser::registry::Signature;
use crate::prelude::*;
use base64::encode;
@ -10,7 +10,7 @@ use mime::Mime;
use std::path::PathBuf;
use std::str::FromStr;
use surf::mime;
use uuid::Uuid;
pub struct Post;
impl PerItemCommand for Post {
@ -20,10 +20,10 @@ impl PerItemCommand for Post {
fn signature(&self) -> Signature {
Signature::build(self.name())
.required("path", SyntaxType::Any)
.required("body", SyntaxType::Any)
.named("user", SyntaxType::Any)
.named("password", SyntaxType::Any)
.required("path", SyntaxShape::Any)
.required("body", SyntaxShape::Any)
.named("user", SyntaxShape::Any)
.named("password", SyntaxShape::Any)
.switch("raw")
}
@ -63,7 +63,7 @@ fn run(
file => file.clone(),
};
let path_str = path.as_string()?;
let path_span = path.span();
let path_span = path.tag();
let has_raw = call_info.args.has("raw");
let user = call_info.args.get("user").map(|x| x.as_string().unwrap());
let password = call_info
@ -109,7 +109,7 @@ fn run(
},
source: raw_args.call_info.source,
source_map: raw_args.call_info.source_map,
name_span: raw_args.call_info.name_span,
name_tag: raw_args.call_info.name_tag,
}
};
let mut result = converter.run(new_args.with_input(vec![tagged_contents]), &registry);
@ -143,7 +143,7 @@ pub async fn post(
body: &Tagged<Value>,
user: Option<String>,
password: Option<String>,
span: Span,
tag: Tag,
registry: &CommandRegistry,
raw_args: &RawCommandArgs,
) -> Result<(Option<String>, Value, Tag, SpanSource), ShellError> {
@ -189,7 +189,7 @@ pub async fn post(
},
source: raw_args.call_info.source,
source_map: raw_args.call_info.source_map,
name_span: raw_args.call_info.name_span,
name_tag: raw_args.call_info.name_tag,
},
};
let mut result = converter.run(
@ -211,7 +211,7 @@ pub async fn post(
return Err(ShellError::labeled_error(
"Save could not successfully save",
"unexpected data during save",
span,
*tag,
));
}
}
@ -227,7 +227,7 @@ pub async fn post(
return Err(ShellError::labeled_error(
"Could not automatically convert table",
"needs manual conversion",
tag.span,
*tag,
));
}
}
@ -243,13 +243,10 @@ pub async fn post(
ShellError::labeled_error(
"Could not load text from remote url",
"could not load",
span,
tag,
)
})?),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
)),
(mime::APPLICATION, mime::JSON) => Ok((
@ -258,13 +255,10 @@ pub async fn post(
ShellError::labeled_error(
"Could not load text from remote url",
"could not load",
span,
tag,
)
})?),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
)),
(mime::APPLICATION, mime::OCTET_STREAM) => {
@ -272,16 +266,13 @@ pub async fn post(
ShellError::labeled_error(
"Could not load binary file",
"could not load",
span,
tag,
)
})?;
Ok((
None,
Value::Binary(buf),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
))
}
@ -290,16 +281,13 @@ pub async fn post(
ShellError::labeled_error(
"Could not load image file",
"could not load",
span,
tag,
)
})?;
Ok((
Some(image_ty.to_string()),
Value::Binary(buf),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
))
}
@ -309,13 +297,10 @@ pub async fn post(
ShellError::labeled_error(
"Could not load text from remote url",
"could not load",
span,
tag,
)
})?),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
)),
(mime::TEXT, mime::PLAIN) => {
@ -336,13 +321,10 @@ pub async fn post(
ShellError::labeled_error(
"Could not load text from remote url",
"could not load",
span,
tag,
)
})?),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
))
}
@ -352,10 +334,7 @@ pub async fn post(
"Not yet supported MIME type: {} {}",
ty, sub_ty
)),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
)),
}
@ -363,10 +342,7 @@ pub async fn post(
None => Ok((
None,
Value::string(format!("No content type found")),
Tag {
span,
origin: Some(Uuid::new_v4()),
},
tag,
SpanSource::Url(location.to_string()),
)),
},
@ -374,7 +350,7 @@ pub async fn post(
return Err(ShellError::labeled_error(
"URL could not be opened",
"url not found",
span,
tag,
));
}
}
@ -382,7 +358,7 @@ pub async fn post(
Err(ShellError::labeled_error(
"Expected a url",
"needs a url",
span,
tag,
))
}
}

View File

@ -16,7 +16,7 @@ impl WholeStreamCommand for Reject {
}
fn signature(&self) -> Signature {
Signature::build("reject").rest(SyntaxType::Member)
Signature::build("reject").rest(SyntaxShape::Member)
}
fn usage(&self) -> &str {

View File

@ -1,6 +1,6 @@
use crate::commands::command::RunnablePerItemContext;
use crate::errors::ShellError;
use crate::parser::hir::SyntaxType;
use crate::parser::hir::SyntaxShape;
use crate::parser::registry::{CommandRegistry, Signature};
use crate::prelude::*;
use std::path::PathBuf;
@ -20,7 +20,7 @@ impl PerItemCommand for Remove {
fn signature(&self) -> Signature {
Signature::build("rm")
.required("path", SyntaxType::Path)
.required("path", SyntaxShape::Pattern)
.switch("recursive")
}

View File

@ -7,7 +7,7 @@ use std::path::{Path, PathBuf};
pub struct Save;
macro_rules! process_string {
($input:ident, $name_span:ident) => {{
($input:ident, $name_tag:ident) => {{
let mut result_string = String::new();
for res in $input {
match res {
@ -21,7 +21,7 @@ macro_rules! process_string {
yield core::task::Poll::Ready(Err(ShellError::labeled_error(
"Save could not successfully save",
"unexpected data during save",
$name_span,
$name_tag,
)));
}
}
@ -31,7 +31,7 @@ macro_rules! process_string {
}
macro_rules! process_string_return_success {
($result_vec:ident, $name_span:ident) => {{
($result_vec:ident, $name_tag:ident) => {{
let mut result_string = String::new();
for res in $result_vec {
match res {
@ -45,7 +45,7 @@ macro_rules! process_string_return_success {
yield core::task::Poll::Ready(Err(ShellError::labeled_error(
"Save could not successfully save",
"unexpected data during text save",
$name_span,
$name_tag,
)));
}
}
@ -55,7 +55,7 @@ macro_rules! process_string_return_success {
}
macro_rules! process_binary_return_success {
($result_vec:ident, $name_span:ident) => {{
($result_vec:ident, $name_tag:ident) => {{
let mut result_binary: Vec<u8> = Vec::new();
for res in $result_vec {
match res {
@ -71,7 +71,7 @@ macro_rules! process_binary_return_success {
yield core::task::Poll::Ready(Err(ShellError::labeled_error(
"Save could not successfully save",
"unexpected data during binary save",
$name_span,
$name_tag,
)));
}
}
@ -93,7 +93,7 @@ impl WholeStreamCommand for Save {
fn signature(&self) -> Signature {
Signature::build("save")
.optional("path", SyntaxType::Path)
.optional("path", SyntaxShape::Path)
.switch("raw")
}
@ -127,7 +127,7 @@ fn save(
raw_args: RawCommandArgs,
) -> Result<OutputStream, ShellError> {
let mut full_path = PathBuf::from(shell_manager.path());
let name_span = name;
let name_tag = name;
let source_map = source_map.clone();
let stream = async_stream_block! {
@ -145,7 +145,7 @@ fn save(
yield Err(ShellError::labeled_error(
"Save requires a filepath",
"needs path",
name_span,
name_tag,
));
}
},
@ -153,7 +153,7 @@ fn save(
yield Err(ShellError::labeled_error(
"Save requires a filepath",
"needs path",
name_span,
name_tag,
));
}
}
@ -161,7 +161,7 @@ fn save(
yield Err(ShellError::labeled_error(
"Save requires a filepath",
"needs path",
name_span,
name_tag,
));
}
} else {
@ -185,21 +185,21 @@ fn save(
},
source: raw_args.call_info.source,
source_map: raw_args.call_info.source_map,
name_span: raw_args.call_info.name_span,
name_tag: raw_args.call_info.name_tag,
}
};
let mut result = converter.run(new_args.with_input(input), &registry);
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
if converter.is_binary() {
process_binary_return_success!(result_vec, name_span)
process_binary_return_success!(result_vec, name_tag)
} else {
process_string_return_success!(result_vec, name_span)
process_string_return_success!(result_vec, name_tag)
}
} else {
process_string!(input, name_span)
process_string!(input, name_tag)
}
} else {
process_string!(input, name_span)
process_string!(input, name_tag)
}
} else {
Ok(string_from(&input).into_bytes())

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::data::TaggedDictBuilder;
use crate::errors::ShellError;
use crate::prelude::*;
pub struct Shells;
@ -29,10 +29,10 @@ impl WholeStreamCommand for Shells {
fn shells(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let mut shells_out = VecDeque::new();
let span = args.call_info.name_span;
let tag = args.call_info.name_tag;
for (index, shell) in args.shell_manager.shells.lock().unwrap().iter().enumerate() {
let mut dict = TaggedDictBuilder::new(Tag::unknown_origin(span));
let mut dict = TaggedDictBuilder::new(tag);
if index == args.shell_manager.current_shell {
dict.insert(" ", "X".to_string());

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::data::{TaggedDictBuilder, Value};
use crate::errors::ShellError;
use crate::prelude::*;
pub struct Size;
@ -29,7 +29,7 @@ impl WholeStreamCommand for Size {
fn size(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let input = args.input;
let span = args.call_info.name_span;
let tag = args.call_info.name_tag;
Ok(input
.values
.map(move |v| match v.item {
@ -37,9 +37,9 @@ fn size(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream,
_ => Err(ShellError::labeled_error_with_secondary(
"Expected a string from pipeline",
"requires string input",
span,
tag,
"value originates from here",
v.span(),
v.tag(),
)),
})
.to_output_stream())
@ -71,7 +71,7 @@ fn count(contents: &str, tag: impl Into<Tag>) -> Tagged<Value> {
}
let mut dict = TaggedDictBuilder::new(tag);
//TODO: add back in name when we have it in the span
//TODO: add back in name when we have it in the tag
//dict.insert("name", Value::string(name));
dict.insert("lines", Value::int(lines));
dict.insert("words", Value::int(words));

View File

@ -16,7 +16,7 @@ impl WholeStreamCommand for SkipWhile {
fn signature(&self) -> Signature {
Signature::build("skip-while")
.required("condition", SyntaxType::Block)
.required("condition", SyntaxShape::Block)
.filter()
}

View File

@ -15,7 +15,7 @@ impl WholeStreamCommand for SortBy {
}
fn signature(&self) -> Signature {
Signature::build("sort-by").rest(SyntaxType::String)
Signature::build("sort-by").rest(SyntaxShape::String)
}
fn usage(&self) -> &str {

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::errors::ShellError;
use crate::prelude::*;
use log::trace;
@ -21,9 +21,9 @@ impl WholeStreamCommand for SplitColumn {
fn signature(&self) -> Signature {
Signature::build("split-column")
.required("separator", SyntaxType::Any)
.required("separator", SyntaxShape::Any)
.switch("collapse-empty")
.rest(SyntaxType::Member)
.rest(SyntaxShape::Member)
}
fn usage(&self) -> &str {
@ -40,7 +40,11 @@ impl WholeStreamCommand for SplitColumn {
}
fn split_column(
SplitColumnArgs { separator, rest, collapse_empty}: SplitColumnArgs,
SplitColumnArgs {
separator,
rest,
collapse_empty,
}: SplitColumnArgs,
RunnableContext { input, name, .. }: RunnableContext,
) -> Result<OutputStream, ShellError> {
Ok(input
@ -92,7 +96,7 @@ fn split_column(
"requires string input",
name,
"value originates from here",
v.span(),
v.tag(),
)),
})
.to_output_stream())

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::data::{Primitive, Value};
use crate::errors::ShellError;
use crate::prelude::*;
use log::trace;
@ -17,8 +17,7 @@ impl WholeStreamCommand for SplitRow {
}
fn signature(&self) -> Signature {
Signature::build("split-row")
.required("separator", SyntaxType::Any)
Signature::build("split-row").required("separator", SyntaxShape::Any)
}
fn usage(&self) -> &str {
@ -63,7 +62,7 @@ fn split_row(
"requires string input",
name,
"value originates from here",
v.span(),
v.tag(),
)));
result
}

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::data::{TaggedDictBuilder, Value};
use crate::errors::ShellError;
use crate::prelude::*;
pub struct Tags;
@ -36,7 +36,7 @@ fn tags(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream,
let mut tags = TaggedDictBuilder::new(v.tag());
{
let origin = v.origin();
let span = v.span();
let span = v.tag().span;
let mut dict = TaggedDictBuilder::new(v.tag());
dict.insert("start", Value::int(span.start as i64));
dict.insert("end", Value::int(span.end as i64));

View File

@ -190,44 +190,40 @@ fn generic_object_value_to_bson(o: &Dictionary) -> Result<Bson, ShellError> {
Ok(Bson::Document(doc))
}
fn shell_encode_document(
writer: &mut Vec<u8>,
doc: Document,
span: Span,
) -> Result<(), ShellError> {
fn shell_encode_document(writer: &mut Vec<u8>, doc: Document, tag: Tag) -> Result<(), ShellError> {
match encode_document(writer, &doc) {
Err(e) => Err(ShellError::labeled_error(
format!("Failed to encode document due to: {:?}", e),
"requires BSON-compatible document",
span,
tag,
)),
_ => Ok(()),
}
}
fn bson_value_to_bytes(bson: Bson, span: Span) -> Result<Vec<u8>, ShellError> {
fn bson_value_to_bytes(bson: Bson, tag: Tag) -> Result<Vec<u8>, ShellError> {
let mut out = Vec::new();
match bson {
Bson::Array(a) => {
for v in a.into_iter() {
match v {
Bson::Document(d) => shell_encode_document(&mut out, d, span)?,
Bson::Document(d) => shell_encode_document(&mut out, d, tag)?,
_ => {
return Err(ShellError::labeled_error(
format!("All top level values must be Documents, got {:?}", v),
"requires BSON-compatible document",
span,
tag,
))
}
}
}
}
Bson::Document(d) => shell_encode_document(&mut out, d, span)?,
Bson::Document(d) => shell_encode_document(&mut out, d, tag)?,
_ => {
return Err(ShellError::labeled_error(
format!("All top level values must be Documents, got {:?}", bson),
"requires BSON-compatible document",
span,
tag,
))
}
}
@ -236,7 +232,7 @@ fn bson_value_to_bytes(bson: Bson, span: Span) -> Result<Vec<u8>, ShellError> {
fn to_bson(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let name_span = args.name_span();
let name_tag = args.name_tag();
let stream = async_stream_block! {
let input: Vec<Tagged<Value>> = args.input.values.collect().await;
@ -252,23 +248,23 @@ fn to_bson(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
for value in to_process_input {
match value_to_bson_value(&value) {
Ok(bson_value) => {
match bson_value_to_bytes(bson_value, name_span) {
match bson_value_to_bytes(bson_value, name_tag) {
Ok(x) => yield ReturnSuccess::value(
Value::Binary(x).simple_spanned(name_span),
Value::Binary(x).tagged(name_tag),
),
_ => yield Err(ShellError::labeled_error_with_secondary(
"Expected a table with BSON-compatible structure.span() from pipeline",
"Expected a table with BSON-compatible structure.tag() from pipeline",
"requires BSON-compatible input",
name_span,
name_tag,
"originates from here".to_string(),
value.span(),
value.tag(),
)),
}
}
_ => yield Err(ShellError::labeled_error(
"Expected a table with BSON-compatible structure from pipeline",
"requires BSON-compatible input",
name_span))
name_tag))
}
}
};

View File

@ -134,7 +134,7 @@ fn to_csv(
ToCSVArgs { headerless }: ToCSVArgs,
RunnableContext { input, name, .. }: RunnableContext,
) -> Result<OutputStream, ShellError> {
let name_span = name;
let name_tag = name;
let stream = async_stream_block! {
let input: Vec<Tagged<Value>> = input.values.collect().await;
@ -155,15 +155,15 @@ fn to_csv(
} else {
x
};
yield ReturnSuccess::value(Value::Primitive(Primitive::String(converted)).simple_spanned(name_span))
yield ReturnSuccess::value(Value::Primitive(Primitive::String(converted)).tagged(name_tag))
}
_ => {
yield Err(ShellError::labeled_error_with_secondary(
"Expected a table with CSV-compatible structure.span() from pipeline",
"Expected a table with CSV-compatible structure.tag() from pipeline",
"requires CSV-compatible input",
name_span,
name_tag,
"originates from here".to_string(),
value.span(),
value.tag(),
))
}
}

View File

@ -80,7 +80,7 @@ fn json_list(input: &Vec<Tagged<Value>>) -> Result<Vec<serde_json::Value>, Shell
fn to_json(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let name_span = args.name_span();
let name_tag = args.name_tag();
let stream = async_stream_block! {
let input: Vec<Tagged<Value>> = args.input.values.collect().await;
@ -98,21 +98,21 @@ fn to_json(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
Ok(json_value) => {
match serde_json::to_string(&json_value) {
Ok(x) => yield ReturnSuccess::value(
Value::Primitive(Primitive::String(x)).simple_spanned(name_span),
Value::Primitive(Primitive::String(x)).tagged(name_tag),
),
_ => yield Err(ShellError::labeled_error_with_secondary(
"Expected a table with JSON-compatible structure.span() from pipeline",
"Expected a table with JSON-compatible structure.tag() from pipeline",
"requires JSON-compatible input",
name_span,
name_tag,
"originates from here".to_string(),
value.span(),
value.tag(),
)),
}
}
_ => yield Err(ShellError::labeled_error(
"Expected a table with JSON-compatible structure from pipeline",
"requires JSON-compatible input",
name_span))
name_tag))
}
}
};

View File

@ -200,7 +200,7 @@ fn sqlite_input_stream_to_bytes(
fn to_sqlite(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let name_span = args.name_span();
let name_tag = args.name_tag();
let stream = async_stream_block! {
let input: Vec<Tagged<Value>> = args.input.values.collect().await;
@ -208,9 +208,9 @@ fn to_sqlite(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStre
Ok(out) => yield ReturnSuccess::value(out),
_ => {
yield Err(ShellError::labeled_error(
"Expected a table with SQLite-compatible structure.span() from pipeline",
"Expected a table with SQLite-compatible structure.tag() from pipeline",
"requires SQLite-compatible input",
name_span,
name_tag,
))
},
}

View File

@ -75,7 +75,7 @@ fn collect_values(input: &Vec<Tagged<Value>>) -> Result<Vec<toml::Value>, ShellE
fn to_toml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let name_span = args.name_span();
let name_tag = args.name_tag();
let stream = async_stream_block! {
let input: Vec<Tagged<Value>> = args.input.values.collect().await;
@ -93,21 +93,21 @@ fn to_toml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
Ok(toml_value) => {
match toml::to_string(&toml_value) {
Ok(x) => yield ReturnSuccess::value(
Value::Primitive(Primitive::String(x)).simple_spanned(name_span),
Value::Primitive(Primitive::String(x)).tagged(name_tag),
),
_ => yield Err(ShellError::labeled_error_with_secondary(
"Expected a table with TOML-compatible structure.span() from pipeline",
"Expected a table with TOML-compatible structure.tag() from pipeline",
"requires TOML-compatible input",
name_span,
name_tag,
"originates from here".to_string(),
value.span(),
value.tag(),
)),
}
}
_ => yield Err(ShellError::labeled_error(
"Expected a table with TOML-compatible structure from pipeline",
"requires TOML-compatible input",
name_span))
name_tag))
}
}
};

View File

@ -133,7 +133,7 @@ fn to_tsv(
ToTSVArgs { headerless }: ToTSVArgs,
RunnableContext { input, name, .. }: RunnableContext,
) -> Result<OutputStream, ShellError> {
let name_span = name;
let name_tag = name;
let stream = async_stream_block! {
let input: Vec<Tagged<Value>> = input.values.collect().await;
@ -154,15 +154,15 @@ fn to_tsv(
} else {
x
};
yield ReturnSuccess::value(Value::Primitive(Primitive::String(converted)).simple_spanned(name_span))
yield ReturnSuccess::value(Value::Primitive(Primitive::String(converted)).tagged(name_tag))
}
_ => {
yield Err(ShellError::labeled_error_with_secondary(
"Expected a table with TSV-compatible structure.span() from pipeline",
"Expected a table with TSV-compatible structure.tag() from pipeline",
"requires TSV-compatible input",
name_span,
name_tag,
"originates from here".to_string(),
value.span(),
value.tag(),
))
}
}

View File

@ -76,7 +76,7 @@ pub fn value_to_yaml_value(v: &Tagged<Value>) -> Result<serde_yaml::Value, Shell
fn to_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let name_span = args.name_span();
let name_tag = args.name_tag();
let stream = async_stream_block! {
let input: Vec<Tagged<Value>> = args.input.values.collect().await;
@ -94,21 +94,21 @@ fn to_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
Ok(yaml_value) => {
match serde_yaml::to_string(&yaml_value) {
Ok(x) => yield ReturnSuccess::value(
Value::Primitive(Primitive::String(x)).simple_spanned(name_span),
Value::Primitive(Primitive::String(x)).tagged(name_tag),
),
_ => yield Err(ShellError::labeled_error_with_secondary(
"Expected a table with YAML-compatible structure.span() from pipeline",
"Expected a table with YAML-compatible structure.tag() from pipeline",
"requires YAML-compatible input",
name_span,
name_tag,
"originates from here".to_string(),
value.span(),
value.tag(),
)),
}
}
_ => yield Err(ShellError::labeled_error(
"Expected a table with YAML-compatible structure from pipeline",
"requires YAML-compatible input",
name_span))
name_tag))
}
}
};

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::data::Value;
use crate::errors::ShellError;
use crate::prelude::*;
pub struct Trim;
@ -34,7 +34,7 @@ fn trim(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream,
.values
.map(move |v| {
let string = String::extract(&v)?;
ReturnSuccess::value(Value::string(string.trim()).simple_spanned(v.span()))
ReturnSuccess::value(Value::string(string.trim()).tagged(v.tag()))
})
.to_output_stream())
}

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::data::{Dictionary, Value};
use crate::errors::ShellError;
use crate::parser::registry::Signature;
use crate::prelude::*;
use indexmap::IndexMap;
@ -31,14 +31,14 @@ impl WholeStreamCommand for Version {
pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let args = args.evaluate_once(registry)?;
let span = args.call_info.name_span;
let tag = args.call_info.name_tag;
let mut indexmap = IndexMap::new();
indexmap.insert(
"version".to_string(),
Tagged::from_simple_spanned_item(Value::string(clap::crate_version!()), span),
Value::string(clap::crate_version!()).tagged(tag),
);
let value = Tagged::from_simple_spanned_item(Value::Row(Dictionary::from(indexmap)), span);
let value = Value::Row(Dictionary::from(indexmap)).tagged(tag);
Ok(OutputStream::one(value))
}

View File

@ -1,6 +1,6 @@
use crate::commands::PerItemCommand;
use crate::errors::ShellError;
use crate::parser::hir::SyntaxType;
use crate::parser::hir::SyntaxShape;
use crate::parser::registry;
use crate::prelude::*;
@ -12,8 +12,7 @@ impl PerItemCommand for Where {
}
fn signature(&self) -> registry::Signature {
Signature::build("where")
.required("condition", SyntaxType::Block)
Signature::build("where").required("condition", SyntaxShape::Block)
}
fn usage(&self) -> &str {
@ -43,16 +42,14 @@ impl PerItemCommand for Where {
VecDeque::new()
}
}
Err(e) => {
return Err(e)
}
Err(e) => return Err(e),
}
}
Tagged { tag, .. } => {
return Err(ShellError::labeled_error(
"Expected a condition",
"where needs a condition",
tag.span,
*tag,
))
}
};

View File

@ -1,5 +1,5 @@
use crate::errors::ShellError;
use crate::data::Value;
use crate::errors::ShellError;
use crate::prelude::*;
use crate::commands::WholeStreamCommand;
@ -13,8 +13,7 @@ impl WholeStreamCommand for Which {
}
fn signature(&self) -> Signature {
Signature::build("which")
.required("name", SyntaxType::Any)
Signature::build("which").required("name", SyntaxShape::Any)
}
fn usage(&self) -> &str {
@ -34,7 +33,7 @@ pub fn which(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStre
let args = args.evaluate_once(registry)?;
let mut which_out = VecDeque::new();
let span = args.call_info.name_span;
let tag = args.call_info.name_tag;
if let Some(v) = &args.call_info.args.positional {
if v.len() > 0 {
@ -53,7 +52,7 @@ pub fn which(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStre
return Err(ShellError::labeled_error(
"Expected a filename to find",
"needs a filename",
tag.span,
*tag,
));
}
}
@ -61,14 +60,14 @@ pub fn which(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStre
return Err(ShellError::labeled_error(
"Expected a binary to find",
"needs application name",
span,
tag,
));
}
} else {
return Err(ShellError::labeled_error(
"Expected a binary to find",
"needs application name",
span,
tag,
));
}