forked from extern/nushell
Remove rest_args() from evaluated CommandArgs (#3449)
It was too error prone when positional arguments were used with the rest arguments. Now, you need to explicitly state from which position you want to count the rest args (e.g., `rest(0)`).
This commit is contained in:
parent
e2973d2176
commit
3075e2cfbf
@ -40,7 +40,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
let args = args.evaluate_once()?;
|
||||||
|
|
||||||
let column_paths: Vec<_> = args.rest_args()?;
|
let column_paths: Vec<_> = args.rest(0)?;
|
||||||
|
|
||||||
let result: Vec<Value> = args
|
let result: Vec<Value> = args
|
||||||
.input
|
.input
|
||||||
|
@ -43,7 +43,7 @@ impl WholeStreamCommand for PathBasename {
|
|||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
let args = args.evaluate_once()?;
|
||||||
let cmd_args = Arc::new(PathBasenameArguments {
|
let cmd_args = Arc::new(PathBasenameArguments {
|
||||||
rest: args.rest_args()?,
|
rest: args.rest(0)?,
|
||||||
replace: args.get_flag("replace")?,
|
replace: args.get_flag("replace")?,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ impl WholeStreamCommand for PathDirname {
|
|||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
let args = args.evaluate_once()?;
|
||||||
let cmd_args = Arc::new(PathDirnameArguments {
|
let cmd_args = Arc::new(PathDirnameArguments {
|
||||||
rest: args.rest_args()?,
|
rest: args.rest(0)?,
|
||||||
replace: args.get_flag("replace")?,
|
replace: args.get_flag("replace")?,
|
||||||
num_levels: args.get_flag("num-levels")?,
|
num_levels: args.get_flag("num-levels")?,
|
||||||
});
|
});
|
||||||
|
@ -35,7 +35,7 @@ impl WholeStreamCommand for PathExists {
|
|||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
let args = args.evaluate_once()?;
|
||||||
let cmd_args = Arc::new(PathExistsArguments {
|
let cmd_args = Arc::new(PathExistsArguments {
|
||||||
rest: args.rest_args()?,
|
rest: args.rest(0)?,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(operate(args.input, &action, tag.span, cmd_args))
|
Ok(operate(args.input, &action, tag.span, cmd_args))
|
||||||
|
@ -35,7 +35,7 @@ impl WholeStreamCommand for PathExpand {
|
|||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
let args = args.evaluate_once()?;
|
||||||
let cmd_args = Arc::new(PathExpandArguments {
|
let cmd_args = Arc::new(PathExpandArguments {
|
||||||
rest: args.rest_args()?,
|
rest: args.rest(0)?,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(operate(args.input, &action, tag.span, cmd_args))
|
Ok(operate(args.input, &action, tag.span, cmd_args))
|
||||||
|
@ -48,7 +48,7 @@ the output of 'path parse' and 'path split' subcommands."#
|
|||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
let args = args.evaluate_once()?;
|
||||||
let cmd_args = Arc::new(PathJoinArguments {
|
let cmd_args = Arc::new(PathJoinArguments {
|
||||||
rest: args.rest_args()?,
|
rest: args.rest(0)?,
|
||||||
append: args.get_flag("append")?,
|
append: args.get_flag("append")?,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ On Windows, an extra 'prefix' column is added."#
|
|||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
let args = args.evaluate_once()?;
|
||||||
let cmd_args = Arc::new(PathParseArguments {
|
let cmd_args = Arc::new(PathParseArguments {
|
||||||
rest: args.rest_args()?,
|
rest: args.rest(0)?,
|
||||||
extension: args.get_flag("extension")?,
|
extension: args.get_flag("extension")?,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ impl WholeStreamCommand for PathSplit {
|
|||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
let args = args.evaluate_once()?;
|
||||||
let cmd_args = Arc::new(PathSplitArguments {
|
let cmd_args = Arc::new(PathSplitArguments {
|
||||||
rest: args.rest_args()?,
|
rest: args.rest(0)?,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(operate_split(args.input, &action, tag.span, cmd_args))
|
Ok(operate_split(args.input, &action, tag.span, cmd_args))
|
||||||
|
@ -36,7 +36,7 @@ impl WholeStreamCommand for PathType {
|
|||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
let args = args.evaluate_once()?;
|
||||||
let cmd_args = Arc::new(PathTypeArguments {
|
let cmd_args = Arc::new(PathTypeArguments {
|
||||||
rest: args.rest_args()?,
|
rest: args.rest(0)?,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(operate(args.input, &action, tag.span, cmd_args))
|
Ok(operate(args.input, &action, tag.span, cmd_args))
|
||||||
|
@ -46,7 +46,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let (options, input) = args.extract(|params| {
|
let (options, input) = args.extract(|params| {
|
||||||
Ok(Arguments {
|
Ok(Arguments {
|
||||||
column_paths: params.rest_args()?,
|
column_paths: params.rest(0)?,
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ where
|
|||||||
{
|
{
|
||||||
let (options, input) = args.extract(|params| {
|
let (options, input) = args.extract(|params| {
|
||||||
Ok(Arguments {
|
Ok(Arguments {
|
||||||
column_paths: params.rest_args()?,
|
column_paths: params.rest(0)?,
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let (options, input) = args.extract(|params| {
|
let (options, input) = args.extract(|params| {
|
||||||
Ok(Arguments {
|
Ok(Arguments {
|
||||||
column_paths: params.rest_args()?,
|
column_paths: params.rest(0)?,
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
|||||||
Ok(Arguments {
|
Ok(Arguments {
|
||||||
decimals: params.get_flag("decimals")?,
|
decimals: params.get_flag("decimals")?,
|
||||||
group_digits: false,
|
group_digits: false,
|
||||||
column_paths: params.rest_args()?,
|
column_paths: params.rest(0)?,
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let (options, input) = args.extract(|params| {
|
let (options, input) = args.extract(|params| {
|
||||||
Ok(Arguments {
|
Ok(Arguments {
|
||||||
column_paths: params.rest_args()?,
|
column_paths: params.rest(0)?,
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
|||||||
Ok(Arc::new(Arguments {
|
Ok(Arc::new(Arguments {
|
||||||
length: params.req_named("length")?,
|
length: params.req_named("length")?,
|
||||||
character: params.req_named("character")?,
|
character: params.req_named("character")?,
|
||||||
column_paths: params.rest_args()?,
|
column_paths: params.rest(0)?,
|
||||||
}))
|
}))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let (options, input) = args.extract(|params| {
|
let (options, input) = args.extract(|params| {
|
||||||
Ok(Arguments {
|
Ok(Arguments {
|
||||||
column_paths: params.rest_args()?,
|
column_paths: params.rest(0)?,
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
|||||||
Ok(Arc::new(Arguments {
|
Ok(Arc::new(Arguments {
|
||||||
length: params.req_named("length")?,
|
length: params.req_named("length")?,
|
||||||
character: params.req_named("character")?,
|
character: params.req_named("character")?,
|
||||||
column_paths: params.rest_args()?,
|
column_paths: params.rest(0)?,
|
||||||
}))
|
}))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ struct DatetimeFormat(String);
|
|||||||
|
|
||||||
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let (options, input) = args.extract(|params| {
|
let (options, input) = args.extract(|params| {
|
||||||
let (column_paths, _) = arguments(&mut params.rest_args()?)?;
|
let (column_paths, _) = arguments(&mut params.rest(0)?)?;
|
||||||
|
|
||||||
Ok(Arguments {
|
Ok(Arguments {
|
||||||
timezone: params.get_flag("timezone")?,
|
timezone: params.get_flag("timezone")?,
|
||||||
|
@ -49,7 +49,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let (options, input) = args.extract(|params| {
|
let (options, input) = args.extract(|params| {
|
||||||
Ok(Arguments {
|
Ok(Arguments {
|
||||||
column_paths: params.rest_args()?,
|
column_paths: params.rest(0)?,
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
|
|
||||||
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let (options, input) = args.extract(|params| {
|
let (options, input) = args.extract(|params| {
|
||||||
let (column_paths, _) = arguments(&mut params.rest_args()?)?;
|
let (column_paths, _) = arguments(&mut params.rest(0)?)?;
|
||||||
|
|
||||||
Ok(Arguments {
|
Ok(Arguments {
|
||||||
radix: params.get_flag("radix")?,
|
radix: params.get_flag("radix")?,
|
||||||
|
@ -26,7 +26,7 @@ where
|
|||||||
let (options, input) = args.extract(|params| {
|
let (options, input) = args.extract(|params| {
|
||||||
Ok(Arc::new(Arguments {
|
Ok(Arc::new(Arguments {
|
||||||
character: params.get_flag("char")?,
|
character: params.get_flag("char")?,
|
||||||
column_paths: params.rest_args()?,
|
column_paths: params.rest(0)?,
|
||||||
}))
|
}))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn operate(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let (options, input) = args.extract(|params| {
|
let (options, input) = args.extract(|params| {
|
||||||
Ok(Arguments {
|
Ok(Arguments {
|
||||||
column_paths: params.rest_args()?,
|
column_paths: params.rest(0)?,
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -201,10 +201,6 @@ impl EvaluatedCommandArgsWithoutInput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rest_args<T: FromValue>(&self) -> Result<Vec<T>, ShellError> {
|
|
||||||
self.rest(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn rest<T: FromValue>(&self, starting_pos: usize) -> Result<Vec<T>, ShellError> {
|
pub fn rest<T: FromValue>(&self, starting_pos: usize) -> Result<Vec<T>, ShellError> {
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user