mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
Short-hand flags (#1378)
* typo fixes * Change signature to take in short-hand flags * update help information * Parse short-hand flags as their long counterparts * lints * Modified a couple tests to use shorthand flags
This commit is contained in:
parent
2ab8d035e6
commit
c0be02a434
46 changed files with 344 additions and 110 deletions
|
@ -183,7 +183,11 @@ fn with_empty_context(source: &Text, callback: impl FnOnce(ExpandContext)) {
|
|||
SyntaxShape::Pattern,
|
||||
"a path to get the directory contents from",
|
||||
)
|
||||
.switch("full", "list all available columns for each entry"),
|
||||
.switch(
|
||||
"full",
|
||||
"list all available columns for each entry",
|
||||
Some('f'),
|
||||
),
|
||||
);
|
||||
|
||||
callback(ExpandContext::new(Box::new(registry), source, None))
|
||||
|
|
|
@ -361,9 +361,20 @@ impl SpannedToken {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn as_flag(&self, value: &str, source: &Text) -> Option<Flag> {
|
||||
pub(crate) fn as_flag(&self, value: &str, short: Option<char>, source: &Text) -> Option<Flag> {
|
||||
match self.unspanned() {
|
||||
Token::Flag(flag @ Flag { .. }) if value == flag.name().slice(source) => Some(*flag),
|
||||
Token::Flag(flag @ Flag { .. }) => {
|
||||
let name = flag.name().slice(source);
|
||||
let is_long = flag.kind == FlagKind::Longhand && value == name;
|
||||
let is_short = flag.kind == FlagKind::Shorthand
|
||||
&& short.is_some()
|
||||
&& short == name.chars().nth(0);
|
||||
if is_long || is_short {
|
||||
Some(*flag)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ pub fn parse_command_tail(
|
|||
trace!(target: "nu::parse::trace_remaining", "looking for {} : {:?}", name, kind);
|
||||
|
||||
match &kind.0 {
|
||||
NamedType::Switch => {
|
||||
let switch = extract_switch(name, tail);
|
||||
NamedType::Switch(s) => {
|
||||
let switch = extract_switch(name, *s, tail);
|
||||
|
||||
match switch {
|
||||
None => named.insert_switch(name, None),
|
||||
|
@ -45,8 +45,8 @@ pub fn parse_command_tail(
|
|||
}
|
||||
}
|
||||
}
|
||||
NamedType::Mandatory(syntax_type) => {
|
||||
match extract_mandatory(config, name, tail, command_span) {
|
||||
NamedType::Mandatory(s, syntax_type) => {
|
||||
match extract_mandatory(config, name, *s, tail, command_span) {
|
||||
Err(err) => {
|
||||
// remember this error, but continue coloring
|
||||
found_error = Some(err);
|
||||
|
@ -71,8 +71,8 @@ pub fn parse_command_tail(
|
|||
}
|
||||
}
|
||||
}
|
||||
NamedType::Optional(syntax_type) => {
|
||||
match extract_optional(name, tail) {
|
||||
NamedType::Optional(s, syntax_type) => {
|
||||
match extract_optional(name, *s, tail) {
|
||||
Err(err) => {
|
||||
// remember this error, but continue coloring
|
||||
found_error = Some(err);
|
||||
|
@ -270,10 +270,14 @@ fn expand_spaced_expr<
|
|||
|
||||
fn extract_switch(
|
||||
name: &str,
|
||||
short: Option<char>,
|
||||
tokens: &mut hir::TokensIterator<'_>,
|
||||
) -> Option<(usize, Spanned<Flag>)> {
|
||||
let source = tokens.source();
|
||||
let switch = tokens.extract(|t| t.as_flag(name, &source).map(|flag| flag.spanned(t.span())));
|
||||
let switch = tokens.extract(|t| {
|
||||
t.as_flag(name, short, &source)
|
||||
.map(|flag| flag.spanned(t.span()))
|
||||
});
|
||||
|
||||
match switch {
|
||||
None => None,
|
||||
|
@ -287,11 +291,15 @@ fn extract_switch(
|
|||
fn extract_mandatory(
|
||||
config: &Signature,
|
||||
name: &str,
|
||||
short: Option<char>,
|
||||
tokens: &mut hir::TokensIterator<'_>,
|
||||
span: Span,
|
||||
) -> Result<(usize, Spanned<Flag>), ParseError> {
|
||||
let source = tokens.source();
|
||||
let flag = tokens.extract(|t| t.as_flag(name, &source).map(|flag| flag.spanned(t.span())));
|
||||
let flag = tokens.extract(|t| {
|
||||
t.as_flag(name, short, &source)
|
||||
.map(|flag| flag.spanned(t.span()))
|
||||
});
|
||||
|
||||
match flag {
|
||||
None => Err(ParseError::argument_error(
|
||||
|
@ -308,10 +316,14 @@ fn extract_mandatory(
|
|||
|
||||
fn extract_optional(
|
||||
name: &str,
|
||||
short: Option<char>,
|
||||
tokens: &mut hir::TokensIterator<'_>,
|
||||
) -> Result<Option<(usize, Spanned<Flag>)>, ParseError> {
|
||||
let source = tokens.source();
|
||||
let flag = tokens.extract(|t| t.as_flag(name, &source).map(|flag| flag.spanned(t.span())));
|
||||
let flag = tokens.extract(|t| {
|
||||
t.as_flag(name, short, &source)
|
||||
.map(|flag| flag.spanned(t.span()))
|
||||
});
|
||||
|
||||
match flag {
|
||||
None => Ok(None),
|
||||
|
|
|
@ -7,18 +7,28 @@ use serde::{Deserialize, Serialize};
|
|||
/// The types of named parameter that a command can have
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub enum NamedType {
|
||||
/// A flag without any associated argument. eg) `foo --bar`
|
||||
Switch,
|
||||
/// A mandatory flag, with associated argument. eg) `foo --required xyz`
|
||||
Mandatory(SyntaxShape),
|
||||
/// An optional flag, with associated argument. eg) `foo --optional abc`
|
||||
Optional(SyntaxShape),
|
||||
/// A flag without any associated argument. eg) `foo --bar, foo -b`
|
||||
Switch(Option<char>),
|
||||
/// A mandatory flag, with associated argument. eg) `foo --required xyz, foo -r xyz`
|
||||
Mandatory(Option<char>, SyntaxShape),
|
||||
/// An optional flag, with associated argument. eg) `foo --optional abc, foo -o abc`
|
||||
Optional(Option<char>, SyntaxShape),
|
||||
}
|
||||
|
||||
impl NamedType {
|
||||
pub fn get_short(&self) -> Option<char> {
|
||||
match self {
|
||||
NamedType::Switch(s) => *s,
|
||||
NamedType::Mandatory(s, _) => *s,
|
||||
NamedType::Optional(s, _) => *s,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The type of positional arguments
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum PositionalType {
|
||||
/// A mandatory postional argument with the expected shape of the value
|
||||
/// A mandatory positional argument with the expected shape of the value
|
||||
Mandatory(String, SyntaxShape),
|
||||
/// An optional positional argument with the expected shape of the value
|
||||
Optional(String, SyntaxShape),
|
||||
|
@ -120,7 +130,10 @@ impl Signature {
|
|||
pub fn allowed(&self) -> Vec<String> {
|
||||
let mut allowed = indexmap::IndexSet::new();
|
||||
|
||||
for (name, _) in &self.named {
|
||||
for (name, (t, _)) in &self.named {
|
||||
if let Some(c) = t.get_short() {
|
||||
allowed.insert(format!("-{}", c));
|
||||
}
|
||||
allowed.insert(format!("--{}", name));
|
||||
}
|
||||
|
||||
|
@ -157,14 +170,14 @@ impl PrettyDebugWithSource for Signature {
|
|||
}
|
||||
|
||||
impl Signature {
|
||||
/// Create a new command signagure with the given name
|
||||
/// Create a new command signature with the given name
|
||||
pub fn new(name: impl Into<String>) -> Signature {
|
||||
Signature {
|
||||
name: name.into(),
|
||||
usage: String::new(),
|
||||
positional: vec![],
|
||||
rest_positional: None,
|
||||
named: indexmap::indexmap! {"help".into() => (NamedType::Switch, "Display this help message".into())},
|
||||
named: indexmap::indexmap! {"help".into() => (NamedType::Switch(Some('h')), "Display this help message".into())},
|
||||
is_filter: false,
|
||||
yields: None,
|
||||
input: None,
|
||||
|
@ -218,9 +231,16 @@ impl Signature {
|
|||
name: impl Into<String>,
|
||||
ty: impl Into<SyntaxShape>,
|
||||
desc: impl Into<String>,
|
||||
short: Option<char>,
|
||||
) -> Signature {
|
||||
self.named
|
||||
.insert(name.into(), (NamedType::Optional(ty.into()), desc.into()));
|
||||
let s = short.and_then(|c| {
|
||||
debug_assert!(!self.get_shorts().contains(&c));
|
||||
Some(c)
|
||||
});
|
||||
self.named.insert(
|
||||
name.into(),
|
||||
(NamedType::Optional(s, ty.into()), desc.into()),
|
||||
);
|
||||
|
||||
self
|
||||
}
|
||||
|
@ -231,17 +251,35 @@ impl Signature {
|
|||
name: impl Into<String>,
|
||||
ty: impl Into<SyntaxShape>,
|
||||
desc: impl Into<String>,
|
||||
short: Option<char>,
|
||||
) -> Signature {
|
||||
self.named
|
||||
.insert(name.into(), (NamedType::Mandatory(ty.into()), desc.into()));
|
||||
let s = short.and_then(|c| {
|
||||
debug_assert!(!self.get_shorts().contains(&c));
|
||||
Some(c)
|
||||
});
|
||||
|
||||
self.named.insert(
|
||||
name.into(),
|
||||
(NamedType::Mandatory(s, ty.into()), desc.into()),
|
||||
);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
/// Add a switch to the signature
|
||||
pub fn switch(mut self, name: impl Into<String>, desc: impl Into<String>) -> Signature {
|
||||
pub fn switch(
|
||||
mut self,
|
||||
name: impl Into<String>,
|
||||
desc: impl Into<String>,
|
||||
short: Option<char>,
|
||||
) -> Signature {
|
||||
let s = short.and_then(|c| {
|
||||
debug_assert!(!self.get_shorts().contains(&c));
|
||||
Some(c)
|
||||
});
|
||||
|
||||
self.named
|
||||
.insert(name.into(), (NamedType::Switch, desc.into()));
|
||||
.insert(name.into(), (NamedType::Switch(s), desc.into()));
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -268,4 +306,15 @@ impl Signature {
|
|||
self.input = Some(ty);
|
||||
self
|
||||
}
|
||||
|
||||
/// Get list of the short-hand flags
|
||||
pub fn get_shorts(&self) -> Vec<char> {
|
||||
let mut shorts = Vec::new();
|
||||
for (_, (t, _)) in &self.named {
|
||||
if let Some(c) = t.get_short() {
|
||||
shorts.push(c);
|
||||
}
|
||||
}
|
||||
shorts
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ impl Plugin for BinaryView {
|
|||
fn config(&mut self) -> Result<Signature, ShellError> {
|
||||
Ok(Signature::build("binaryview")
|
||||
.desc("Autoview of binary data.")
|
||||
.switch("lores", "use low resolution output mode"))
|
||||
.switch("lores", "use low resolution output mode", Some('l')))
|
||||
}
|
||||
|
||||
fn sink(&mut self, call_info: CallInfo, input: Vec<Value>) {
|
||||
|
|
|
@ -15,7 +15,7 @@ impl Plugin for Fetch {
|
|||
SyntaxShape::Path,
|
||||
"the URL to fetch the contents from",
|
||||
)
|
||||
.switch("raw", "fetch contents as text rather than a table")
|
||||
.switch("raw", "fetch contents as text rather than a table", Some('r'))
|
||||
.filter())
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,21 @@ impl Plugin for Inc {
|
|||
fn config(&mut self) -> Result<Signature, ShellError> {
|
||||
Ok(Signature::build("inc")
|
||||
.desc("Increment a value or version. Optionally use the column of a table.")
|
||||
.switch("major", "increment the major version (eg 1.2.1 -> 2.0.0)")
|
||||
.switch("minor", "increment the minor version (eg 1.2.1 -> 1.3.0)")
|
||||
.switch("patch", "increment the patch version (eg 1.2.1 -> 1.2.2)")
|
||||
.switch(
|
||||
"major",
|
||||
"increment the major version (eg 1.2.1 -> 2.0.0)",
|
||||
Some('M'),
|
||||
)
|
||||
.switch(
|
||||
"minor",
|
||||
"increment the minor version (eg 1.2.1 -> 1.3.0)",
|
||||
Some('m'),
|
||||
)
|
||||
.switch(
|
||||
"patch",
|
||||
"increment the patch version (eg 1.2.1 -> 1.2.2)",
|
||||
Some('p'),
|
||||
)
|
||||
.rest(SyntaxShape::ColumnPath, "the column(s) to update")
|
||||
.filter())
|
||||
}
|
||||
|
|
|
@ -12,23 +12,35 @@ impl Plugin for Post {
|
|||
.desc("Post content to a url and retrieve data as a table if possible.")
|
||||
.required("path", SyntaxShape::Any, "the URL to post to")
|
||||
.required("body", SyntaxShape::Any, "the contents of the post body")
|
||||
.named("user", SyntaxShape::Any, "the username when authenticating")
|
||||
.named(
|
||||
"user",
|
||||
SyntaxShape::Any,
|
||||
"the username when authenticating",
|
||||
Some('u'),
|
||||
)
|
||||
.named(
|
||||
"password",
|
||||
SyntaxShape::Any,
|
||||
"the password when authenticating",
|
||||
Some('p'),
|
||||
)
|
||||
.named(
|
||||
"content-type",
|
||||
SyntaxShape::Any,
|
||||
"the MIME type of content to post",
|
||||
Some('t'),
|
||||
)
|
||||
.named(
|
||||
"content-length",
|
||||
SyntaxShape::Any,
|
||||
"the length of the content being posted",
|
||||
Some('l'),
|
||||
)
|
||||
.switch(
|
||||
"raw",
|
||||
"return values as a string instead of a table",
|
||||
Some('r'),
|
||||
)
|
||||
.switch("raw", "return values as a string instead of a table")
|
||||
.filter())
|
||||
}
|
||||
|
||||
|
|
|
@ -15,19 +15,26 @@ impl Plugin for Str {
|
|||
fn config(&mut self) -> Result<Signature, ShellError> {
|
||||
Ok(Signature::build("str")
|
||||
.desc("Apply string function. Optional use the column of a table")
|
||||
.switch("downcase", "convert string to lowercase")
|
||||
.switch("upcase", "convert string to uppercase")
|
||||
.switch("to-int", "convert string to integer")
|
||||
.named("replace", SyntaxShape::String, "replaces the string")
|
||||
.switch("downcase", "convert string to lowercase", Some('d'))
|
||||
.switch("upcase", "convert string to uppercase", Some('U'))
|
||||
.switch("to-int", "convert string to integer", Some('i'))
|
||||
.named(
|
||||
"replace",
|
||||
SyntaxShape::String,
|
||||
"replaces the string",
|
||||
Some('r'),
|
||||
)
|
||||
.named(
|
||||
"find-replace",
|
||||
SyntaxShape::Any,
|
||||
"finds and replaces [pattern replacement]",
|
||||
Some('f'),
|
||||
)
|
||||
.named(
|
||||
"substring",
|
||||
SyntaxShape::String,
|
||||
"convert string to portion of original, requires \"start,end\"",
|
||||
Some('s'),
|
||||
)
|
||||
.rest(SyntaxShape::ColumnPath, "the column(s) to convert")
|
||||
.filter())
|
||||
|
|
|
@ -31,21 +31,34 @@ impl WholeStreamCommand for Config {
|
|||
"load",
|
||||
SyntaxShape::Path,
|
||||
"load the config from the path give",
|
||||
Some('l'),
|
||||
)
|
||||
.named(
|
||||
"set",
|
||||
SyntaxShape::Any,
|
||||
"set a value in the config, eg) --set [key value]",
|
||||
Some('s'),
|
||||
)
|
||||
.named(
|
||||
"set_into",
|
||||
SyntaxShape::Member,
|
||||
"sets a variable from values in the pipeline",
|
||||
Some('i'),
|
||||
)
|
||||
.named("get", SyntaxShape::Any, "get a value from the config")
|
||||
.named("remove", SyntaxShape::Any, "remove a value from the config")
|
||||
.switch("clear", "clear the config")
|
||||
.switch("path", "return the path to the config file")
|
||||
.named(
|
||||
"get",
|
||||
SyntaxShape::Any,
|
||||
"get a value from the config",
|
||||
Some('g'),
|
||||
)
|
||||
.named(
|
||||
"remove",
|
||||
SyntaxShape::Any,
|
||||
"remove a value from the config",
|
||||
Some('r'),
|
||||
)
|
||||
.switch("clear", "clear the config", Some('c'))
|
||||
.switch("path", "return the path to the config file", Some('p'))
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -24,7 +24,11 @@ impl PerItemCommand for Cpy {
|
|||
Signature::build("cp")
|
||||
.required("src", SyntaxShape::Pattern, "the place to copy from")
|
||||
.required("dst", SyntaxShape::Path, "the place to copy to")
|
||||
.switch("recursive", "copy recursively through subdirectories")
|
||||
.switch(
|
||||
"recursive",
|
||||
"copy recursively through subdirectories",
|
||||
Some('r'),
|
||||
)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -18,8 +18,8 @@ impl WholeStreamCommand for Date {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("date")
|
||||
.switch("utc", "use universal time (UTC)")
|
||||
.switch("local", "use the local time")
|
||||
.switch("utc", "use universal time (UTC)", Some('u'))
|
||||
.switch("local", "use the local time", Some('l'))
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -16,7 +16,7 @@ impl WholeStreamCommand for Debug {
|
|||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("debug").switch("raw", "Prints the raw value representation.")
|
||||
Signature::build("debug").switch("raw", "Prints the raw value representation.", Some('r'))
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -40,14 +40,33 @@ impl PerItemCommand for Du {
|
|||
fn signature(&self) -> Signature {
|
||||
Signature::build(NAME)
|
||||
.optional("path", SyntaxShape::Pattern, "starting directory")
|
||||
.switch("all", "Output File sizes as well as directory sizes")
|
||||
.switch("deref", "Dereference symlinks to their targets for size")
|
||||
.named("exclude", SyntaxShape::Pattern, "Exclude these file names")
|
||||
.named("max-depth", SyntaxShape::Int, "Directory recursion limit")
|
||||
.switch(
|
||||
"all",
|
||||
"Output File sizes as well as directory sizes",
|
||||
Some('a'),
|
||||
)
|
||||
.switch(
|
||||
"deref",
|
||||
"Dereference symlinks to their targets for size",
|
||||
Some('r'),
|
||||
)
|
||||
.named(
|
||||
"exclude",
|
||||
SyntaxShape::Pattern,
|
||||
"Exclude these file names",
|
||||
Some('x'),
|
||||
)
|
||||
.named(
|
||||
"max-depth",
|
||||
SyntaxShape::Int,
|
||||
"Directory recursion limit",
|
||||
Some('d'),
|
||||
)
|
||||
.named(
|
||||
"min-size",
|
||||
SyntaxShape::Int,
|
||||
"Exclude files below this size",
|
||||
Some('m'),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ impl WholeStreamCommand for EvaluateBy {
|
|||
"evaluate_with",
|
||||
SyntaxShape::String,
|
||||
"the name of the column to evaluate by",
|
||||
Some('w'),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ impl WholeStreamCommand for Exit {
|
|||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("exit").switch("now", "exit out of the shell immediately")
|
||||
Signature::build("exit").switch("now", "exit out of the shell immediately", Some('n'))
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -23,8 +23,13 @@ impl WholeStreamCommand for FromCSV {
|
|||
"separator",
|
||||
SyntaxShape::String,
|
||||
"a character to separate columns, defaults to ','",
|
||||
Some('s'),
|
||||
)
|
||||
.switch(
|
||||
"headerless",
|
||||
"don't treat the first row as column names",
|
||||
None,
|
||||
)
|
||||
.switch("headerless", "don't treat the first row as column names")
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -16,7 +16,11 @@ impl WholeStreamCommand for FromJSON {
|
|||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("from-json").switch("objects", "treat each line as a separate value")
|
||||
Signature::build("from-json").switch(
|
||||
"objects",
|
||||
"treat each line as a separate value",
|
||||
Some('o'),
|
||||
)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -19,8 +19,11 @@ impl WholeStreamCommand for FromODS {
|
|||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("from-ods")
|
||||
.switch("headerless", "don't treat the first row as column names")
|
||||
Signature::build("from-ods").switch(
|
||||
"headerless",
|
||||
"don't treat the first row as column names",
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -27,12 +27,17 @@ impl WholeStreamCommand for FromSSV {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build(STRING_REPRESENTATION)
|
||||
.switch("headerless", "don't treat the first row as column names")
|
||||
.switch("aligned-columns", "assume columns are aligned")
|
||||
.switch(
|
||||
"headerless",
|
||||
"don't treat the first row as column names",
|
||||
None,
|
||||
)
|
||||
.switch("aligned-columns", "assume columns are aligned", Some('a'))
|
||||
.named(
|
||||
"minimum-spaces",
|
||||
SyntaxShape::Int,
|
||||
"the mininum spaces to separate columns",
|
||||
"the minimum spaces to separate columns",
|
||||
Some('m'),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,11 @@ impl WholeStreamCommand for FromTSV {
|
|||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("from-tsv")
|
||||
.switch("headerless", "don't treat the first row as column names")
|
||||
Signature::build("from-tsv").switch(
|
||||
"headerless",
|
||||
"don't treat the first row as column names",
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -19,8 +19,11 @@ impl WholeStreamCommand for FromXLSX {
|
|||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("from-xlsx")
|
||||
.switch("headerless", "don't treat the first row as column names")
|
||||
Signature::build("from-xlsx").switch(
|
||||
"headerless",
|
||||
"don't treat the first row as column names",
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -171,34 +171,67 @@ pub(crate) fn get_help(
|
|||
if !signature.named.is_empty() {
|
||||
long_desc.push_str("\nflags:\n");
|
||||
for (flag, ty) in signature.named {
|
||||
match ty.0 {
|
||||
NamedType::Switch => {
|
||||
long_desc.push_str(&format!(
|
||||
let msg = match ty.0 {
|
||||
NamedType::Switch(s) => {
|
||||
if let Some(c) = s {
|
||||
format!(
|
||||
" -{}, --{}{} {}\n",
|
||||
c,
|
||||
flag,
|
||||
if !ty.1.is_empty() { ":" } else { "" },
|
||||
ty.1
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
" --{}{} {}\n",
|
||||
flag,
|
||||
if !ty.1.is_empty() { ":" } else { "" },
|
||||
ty.1
|
||||
));
|
||||
)
|
||||
}
|
||||
NamedType::Mandatory(m) => {
|
||||
long_desc.push_str(&format!(
|
||||
}
|
||||
NamedType::Mandatory(s, m) => {
|
||||
if let Some(c) = s {
|
||||
format!(
|
||||
" -{}, --{} <{}> (required parameter){} {}\n",
|
||||
c,
|
||||
flag,
|
||||
m.display(),
|
||||
if !ty.1.is_empty() { ":" } else { "" },
|
||||
ty.1
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
" --{} <{}> (required parameter){} {}\n",
|
||||
flag,
|
||||
m.display(),
|
||||
if !ty.1.is_empty() { ":" } else { "" },
|
||||
ty.1
|
||||
));
|
||||
)
|
||||
}
|
||||
NamedType::Optional(o) => {
|
||||
long_desc.push_str(&format!(
|
||||
}
|
||||
NamedType::Optional(s, o) => {
|
||||
if let Some(c) = s {
|
||||
format!(
|
||||
" -{}, --{} <{}>{} {}\n",
|
||||
c,
|
||||
flag,
|
||||
o.display(),
|
||||
if !ty.1.is_empty() { ":" } else { "" },
|
||||
ty.1
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
" --{} <{}>{} {}\n",
|
||||
flag,
|
||||
o.display(),
|
||||
if !ty.1.is_empty() { ":" } else { "" },
|
||||
ty.1
|
||||
));
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
long_desc.push_str(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ impl PerItemCommand for Kill {
|
|||
"process id of process that is to be killed",
|
||||
)
|
||||
.rest(SyntaxShape::Int, "rest of processes to kill")
|
||||
.switch("force", "forcefully kill the process")
|
||||
.switch("quiet", "won't print anything to the console")
|
||||
.switch("force", "forcefully kill the process", Some('f'))
|
||||
.switch("quiet", "won't print anything to the console", Some('q'))
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -29,11 +29,20 @@ impl PerItemCommand for Ls {
|
|||
SyntaxShape::Pattern,
|
||||
"a path to get the directory contents from",
|
||||
)
|
||||
.switch("full", "list all available columns for each entry")
|
||||
.switch("short-names", "only print the file names and not the path")
|
||||
.switch(
|
||||
"full",
|
||||
"list all available columns for each entry",
|
||||
Some('f'),
|
||||
)
|
||||
.switch(
|
||||
"short-names",
|
||||
"only print the file names and not the path",
|
||||
Some('s'),
|
||||
)
|
||||
.switch(
|
||||
"with-symlink-targets",
|
||||
"display the paths to the target files that symlinks point to",
|
||||
Some('w'),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ impl WholeStreamCommand for MapMaxBy {
|
|||
"column_name",
|
||||
SyntaxShape::String,
|
||||
"the name of the column to map-max the table's rows",
|
||||
Some('c'),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,11 @@ impl PerItemCommand for Open {
|
|||
SyntaxShape::Path,
|
||||
"the file path to load values from",
|
||||
)
|
||||
.switch("raw", "load content as a string insead of a table")
|
||||
.switch(
|
||||
"raw",
|
||||
"load content as a string instead of a table",
|
||||
Some('r'),
|
||||
)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -23,8 +23,16 @@ impl WholeStreamCommand for Pivot {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("pivot")
|
||||
.switch("header-row", "treat the first row as column names")
|
||||
.switch("ignore-titles", "don't pivot the column names into values")
|
||||
.switch(
|
||||
"header-row",
|
||||
"treat the first row as column names",
|
||||
Some('h'),
|
||||
)
|
||||
.switch(
|
||||
"ignore-titles",
|
||||
"don't pivot the column names into values",
|
||||
Some('i'),
|
||||
)
|
||||
.rest(
|
||||
SyntaxShape::String,
|
||||
"the names to give columns once pivoted",
|
||||
|
|
|
@ -23,6 +23,7 @@ impl WholeStreamCommand for ReduceBy {
|
|||
"reduce_with",
|
||||
SyntaxShape::String,
|
||||
"the command to reduce by with",
|
||||
Some('w'),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,9 @@ impl PerItemCommand for Remove {
|
|||
.switch(
|
||||
"trash",
|
||||
"use the platform's recycle bin instead of permanently deleting",
|
||||
Some('t'),
|
||||
)
|
||||
.switch("recursive", "delete subdirectories recursively")
|
||||
.switch("recursive", "delete subdirectories recursively", Some('r'))
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -98,6 +98,7 @@ impl WholeStreamCommand for Save {
|
|||
.switch(
|
||||
"raw",
|
||||
"treat values as-is rather than auto-converting based on file extension",
|
||||
Some('r'),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ impl WholeStreamCommand for SplitBy {
|
|||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Creates a new table with the data from the inner tables splitted by the column given."
|
||||
"Creates a new table with the data from the inner tables split by the column given."
|
||||
}
|
||||
|
||||
fn run(
|
||||
|
|
|
@ -29,7 +29,7 @@ impl WholeStreamCommand for SplitColumn {
|
|||
SyntaxShape::Any,
|
||||
"the character that denotes what separates columns",
|
||||
)
|
||||
.switch("collapse-empty", "remove empty columns")
|
||||
.switch("collapse-empty", "remove empty columns", Some('c'))
|
||||
.rest(SyntaxShape::Member, "column names to give the new columns")
|
||||
}
|
||||
|
||||
|
|
|
@ -28,16 +28,22 @@ impl WholeStreamCommand for TSortBy {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("t-sort-by")
|
||||
.switch("show-columns", "Displays the column names sorted")
|
||||
.switch(
|
||||
"show-columns",
|
||||
"Displays the column names sorted",
|
||||
Some('c'),
|
||||
)
|
||||
.named(
|
||||
"group_by",
|
||||
SyntaxShape::String,
|
||||
"the name of the column to group by",
|
||||
Some('g'),
|
||||
)
|
||||
.named(
|
||||
"split_by",
|
||||
SyntaxShape::String,
|
||||
"the name of the column within the grouped by table to split by",
|
||||
Some('s'),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ impl WholeStreamCommand for Table {
|
|||
"start_number",
|
||||
SyntaxShape::Number,
|
||||
"row number to start viewing from",
|
||||
Some('n'),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ impl WholeStreamCommand for ToCSV {
|
|||
Signature::build("to-csv").switch(
|
||||
"headerless",
|
||||
"do not output the columns names as the first row",
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ impl WholeStreamCommand for ToTSV {
|
|||
Signature::build("to-tsv").switch(
|
||||
"headerless",
|
||||
"do not output the column names as the first row",
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ impl WholeStreamCommand for Which {
|
|||
fn signature(&self) -> Signature {
|
||||
Signature::build("which")
|
||||
.required("application", SyntaxShape::String, "application")
|
||||
.switch("all", "list all executables")
|
||||
.switch("all", "list all executables", Some('a'))
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
|
|
@ -60,9 +60,9 @@ fn signature_dict(signature: Signature, tag: impl Into<Tag>) -> Value {
|
|||
|
||||
for (name, ty) in signature.named.iter() {
|
||||
match ty.0 {
|
||||
NamedType::Mandatory(_) => sig.push_value(for_spec(name, "flag", true, &tag)),
|
||||
NamedType::Optional(_) => sig.push_value(for_spec(name, "flag", false, &tag)),
|
||||
NamedType::Switch => sig.push_value(for_spec(name, "switch", false, &tag)),
|
||||
NamedType::Mandatory(_, _) => sig.push_value(for_spec(name, "flag", true, &tag)),
|
||||
NamedType::Optional(_, _) => sig.push_value(for_spec(name, "flag", false, &tag)),
|
||||
NamedType::Switch(_) => sig.push_value(for_spec(name, "switch", false, &tag)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ fn copies_the_directory_inside_directory_if_path_to_copy_is_directory_and_with_r
|
|||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"cp originals expected --recursive"
|
||||
"cp originals expected -r"
|
||||
);
|
||||
|
||||
assert!(expected_dir.exists());
|
||||
|
|
|
@ -5,7 +5,7 @@ fn lines() {
|
|||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml --raw
|
||||
open cargo_sample.toml -r
|
||||
| lines
|
||||
| skip-while $it != "[dependencies]"
|
||||
| skip 1
|
||||
|
|
|
@ -81,7 +81,7 @@ fn removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
|
|||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"rm --recursive src/*"
|
||||
"rm -r src/*"
|
||||
);
|
||||
|
||||
assert!(!files_exist_at(
|
||||
|
|
|
@ -61,7 +61,7 @@ fn from_json_text_recognizing_objects_independently_to_table() {
|
|||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open katz.txt
|
||||
| from-json --objects
|
||||
| from-json -o
|
||||
| where name == "GorbyPuff"
|
||||
| get rusty_luck
|
||||
| echo $it
|
||||
|
|
|
@ -74,7 +74,7 @@ fn from_ssv_text_treating_first_line_as_data_with_flag() {
|
|||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open oc_get_svc.txt
|
||||
| from-ssv --headerless --aligned-columns
|
||||
| from-ssv --headerless -a
|
||||
| first
|
||||
| get Column1
|
||||
| echo $it
|
||||
|
|
|
@ -65,7 +65,7 @@ fn semversion_major_inc() {
|
|||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open sample.toml | inc package.version --major | get package.version | echo $it"
|
||||
"open sample.toml | inc package.version -M | get package.version | echo $it"
|
||||
);
|
||||
|
||||
assert_eq!(actual, "1.0.0");
|
||||
|
|
|
@ -46,7 +46,7 @@ fn downcases() {
|
|||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open sample.toml | str dependency.name --downcase | get dependency.name | echo $it"
|
||||
"open sample.toml | str dependency.name -d | get dependency.name | echo $it"
|
||||
);
|
||||
|
||||
assert_eq!(actual, "light");
|
||||
|
|
Loading…
Reference in a new issue