Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add descriptions to arguments #882

Merged
merged 2 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/commands/cd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ impl WholeStreamCommand for CD {
}

fn signature(&self) -> Signature {
Signature::build("cd").optional("directory", SyntaxShape::Path)
Signature::build("cd").optional(
"directory",
SyntaxShape::Path,
"the directory to change to",
)
}

fn usage(&self) -> &str {
Expand Down
16 changes: 10 additions & 6 deletions src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ impl WholeStreamCommand for Config {

fn signature(&self) -> Signature {
Signature::build("config")
.named("load", SyntaxShape::Path)
.named("set", SyntaxShape::Any)
.named("get", SyntaxShape::Any)
.named("remove", SyntaxShape::Any)
.switch("clear")
.switch("path")
.named(
"load",
SyntaxShape::Path,
"load the config from the path give",
)
.named("set", SyntaxShape::Any, "set a value in the config")
.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")
}

fn usage(&self) -> &str {
Expand Down
7 changes: 3 additions & 4 deletions src/commands/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ impl PerItemCommand for Cpy {

fn signature(&self) -> Signature {
Signature::build("cp")
.required("src", SyntaxShape::Pattern)
.required("dst", SyntaxShape::Path)
.named("file", SyntaxShape::Any)
.switch("recursive")
.required("src", SyntaxShape::Pattern, "the place to copy from")
.required("dst", SyntaxShape::Path, "the place to copy to")
.switch("recursive", "copy recursively through subdirectories")
}

fn usage(&self) -> &str {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ impl WholeStreamCommand for Date {
}

fn signature(&self) -> Signature {
Signature::build("date").switch("utc").switch("local")
Signature::build("date")
.switch("utc", "use universal time (UTC)")
.switch("local", "use the local time")
}

fn usage(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl PerItemCommand for Echo {
}

fn signature(&self) -> Signature {
Signature::build("echo").rest(SyntaxShape::Any)
Signature::build("echo").rest(SyntaxShape::Any, "the values to echo")
}

fn usage(&self) -> &str {
Expand Down
6 changes: 5 additions & 1 deletion src/commands/enter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ impl PerItemCommand for Enter {
}

fn signature(&self) -> registry::Signature {
Signature::build("enter").required("location", SyntaxShape::Path)
Signature::build("enter").required(
"location",
SyntaxShape::Path,
"the location to create a new shell from",
)
}

fn usage(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl WholeStreamCommand for Exit {
}

fn signature(&self) -> Signature {
Signature::build("exit").switch("now")
Signature::build("exit").switch("now", "exit out of the shell immediately")
}

fn usage(&self) -> &str {
Expand Down
8 changes: 6 additions & 2 deletions src/commands/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ impl PerItemCommand for Fetch {

fn signature(&self) -> Signature {
Signature::build(self.name())
.required("path", SyntaxShape::Path)
.switch("raw")
.required(
"path",
SyntaxShape::Path,
"the URL to fetch the contents from",
)
.switch("raw", "fetch contents as text rather than a table")
}

fn usage(&self) -> &str {
Expand Down
6 changes: 5 additions & 1 deletion src/commands/first.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ impl WholeStreamCommand for First {
}

fn signature(&self) -> Signature {
Signature::build("first").optional("rows", SyntaxShape::Int)
Signature::build("first").optional(
"rows",
SyntaxShape::Int,
"starting from the front, the number of rows to return",
)
}

fn usage(&self) -> &str {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/from_csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ impl WholeStreamCommand for FromCSV {
}

fn signature(&self) -> Signature {
Signature::build("from-csv").switch("headerless")
Signature::build("from-csv")
.switch("headerless", "don't treat the first row as column names")
}

fn usage(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/from_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl WholeStreamCommand for FromJSON {
}

fn signature(&self) -> Signature {
Signature::build("from-json").switch("objects")
Signature::build("from-json").switch("objects", "treat each line as a separate value")
}

fn usage(&self) -> &str {
Expand Down
8 changes: 6 additions & 2 deletions src/commands/from_ssv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ impl WholeStreamCommand for FromSSV {

fn signature(&self) -> Signature {
Signature::build(STRING_REPRESENTATION)
.switch("headerless")
.named("minimum-spaces", SyntaxShape::Int)
.switch("headerless", "don't treat the first row as column names")
.named(
"minimum-spaces",
SyntaxShape::Int,
"the mininum spaces to separate columns",
)
}

fn usage(&self) -> &str {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/from_tsv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ impl WholeStreamCommand for FromTSV {
}

fn signature(&self) -> Signature {
Signature::build("from-tsv").switch("headerless")
Signature::build("from-tsv")
.switch("headerless", "don't treat the first row as column names")
}

fn usage(&self) -> &str {
Expand Down
11 changes: 9 additions & 2 deletions src/commands/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ impl WholeStreamCommand for Get {

fn signature(&self) -> Signature {
Signature::build("get")
.required("member", SyntaxShape::ColumnPath)
.rest(SyntaxShape::ColumnPath)
.required(
"member",
SyntaxShape::ColumnPath,
"the path to the data to get",
)
.rest(
SyntaxShape::ColumnPath,
"optionally return additional data by path",
)
}

fn usage(&self) -> &str {
Expand Down
6 changes: 5 additions & 1 deletion src/commands/group_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ impl WholeStreamCommand for GroupBy {
}

fn signature(&self) -> Signature {
Signature::build("group-by").required("column_name", SyntaxShape::String)
Signature::build("group-by").required(
"column_name",
SyntaxShape::String,
"the name of the column to group by",
)
}

fn usage(&self) -> &str {
Expand Down
59 changes: 50 additions & 9 deletions src/commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl PerItemCommand for Help {
}

fn signature(&self) -> registry::Signature {
Signature::build("help").rest(SyntaxShape::Any)
Signature::build("help").rest(SyntaxShape::Any, "the name of command(s) to get help on")
}

fn usage(&self) -> &str {
Expand Down Expand Up @@ -65,8 +65,8 @@ impl PerItemCommand for Help {
one_liner.push_str("{flags} ");
}

for positional in signature.positional {
match positional {
for positional in &signature.positional {
match &positional.0 {
PositionalType::Mandatory(name, _m) => {
one_liner.push_str(&format!("<{}> ", name));
}
Expand All @@ -77,25 +77,66 @@ impl PerItemCommand for Help {
}

if signature.rest_positional.is_some() {
one_liner.push_str(" ...args");
one_liner.push_str(&format!(" ...args",));
}

long_desc.push_str(&format!("\nUsage:\n > {}\n", one_liner));

if signature.positional.len() > 0 || signature.rest_positional.is_some() {
long_desc.push_str("\nparameters:\n");
for positional in signature.positional {
match positional.0 {
PositionalType::Mandatory(name, _m) => {
long_desc
.push_str(&format!(" <{}> {}\n", name, positional.1));
}
PositionalType::Optional(name, _o) => {
long_desc
.push_str(&format!(" ({}) {}\n", name, positional.1));
}
}
}
if signature.rest_positional.is_some() {
long_desc.push_str(&format!(
" ...args{} {}\n",
if signature.rest_positional.is_some() {
":"
} else {
""
},
signature.rest_positional.unwrap().1
));
}
}
if signature.named.len() > 0 {
long_desc.push_str("\nflags:\n");
for (flag, ty) in signature.named {
match ty {
match ty.0 {
NamedType::Switch => {
long_desc.push_str(&format!(" --{}\n", flag));
long_desc.push_str(&format!(
" --{}{} {}\n",
flag,
if ty.1.len() > 0 { ":" } else { "" },
ty.1
));
}
NamedType::Mandatory(m) => {
long_desc.push_str(&format!(
" --{} <{}> (required parameter)\n",
flag, m
" --{} <{}> (required parameter){} {}\n",
flag,
m,
if ty.1.len() > 0 { ":" } else { "" },
ty.1
));
}
NamedType::Optional(o) => {
long_desc.push_str(&format!(" --{} <{}>\n", flag, o));
long_desc.push_str(&format!(
" --{} <{}>{} {}\n",
flag,
o,
if ty.1.len() > 0 { ":" } else { "" },
ty.1
));
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/commands/last.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ impl WholeStreamCommand for Last {
}

fn signature(&self) -> Signature {
Signature::build("last").optional("rows", SyntaxShape::Number)
Signature::build("last").optional(
"rows",
SyntaxShape::Number,
"starting from the back, the number of rows to return",
)
}

fn usage(&self) -> &str {
Expand Down
6 changes: 5 additions & 1 deletion src/commands/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ impl WholeStreamCommand for LS {
}

fn signature(&self) -> Signature {
Signature::build("ls").optional("path", SyntaxShape::Pattern)
Signature::build("ls").optional(
"path",
SyntaxShape::Pattern,
"a path to get the directory contents from",
)
}

fn usage(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/mkdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl PerItemCommand for Mkdir {
}

fn signature(&self) -> Signature {
Signature::build("mkdir").rest(SyntaxShape::Path)
Signature::build("mkdir").rest(SyntaxShape::Path, "the name(s) of the path(s) to create")
}

fn usage(&self) -> &str {
Expand Down
13 changes: 10 additions & 3 deletions src/commands/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ impl PerItemCommand for Move {

fn signature(&self) -> Signature {
Signature::build("mv")
.required("source", SyntaxShape::Pattern)
.required("destination", SyntaxShape::Path)
.named("file", SyntaxShape::Any)
.required(
"source",
SyntaxShape::Pattern,
"the location to move files/directories from",
)
.required(
"destination",
SyntaxShape::Path,
"the location to move files/directories to",
)
}

fn usage(&self) -> &str {
Expand Down
6 changes: 5 additions & 1 deletion src/commands/nth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ impl WholeStreamCommand for Nth {
}

fn signature(&self) -> Signature {
Signature::build("nth").required("row number", SyntaxShape::Any)
Signature::build("nth").required(
"row number",
SyntaxShape::Any,
"the number of the row to return",
)
}

fn usage(&self) -> &str {
Expand Down
8 changes: 6 additions & 2 deletions src/commands/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ impl PerItemCommand for Open {

fn signature(&self) -> Signature {
Signature::build(self.name())
.required("path", SyntaxShape::Path)
.switch("raw")
.required(
"path",
SyntaxShape::Path,
"the file path to load values from",
)
.switch("raw", "load content as a string insead of a table")
}

fn usage(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/pick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl WholeStreamCommand for Pick {
}

fn signature(&self) -> Signature {
Signature::build("pick").rest(SyntaxShape::Any)
Signature::build("pick").rest(SyntaxShape::Any, "the columns to select from the table")
}

fn usage(&self) -> &str {
Expand Down
9 changes: 6 additions & 3 deletions src/commands/pivot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ impl WholeStreamCommand for Pivot {

fn signature(&self) -> Signature {
Signature::build("pivot")
.switch("header-row")
.switch("ignore-titles")
.rest(SyntaxShape::String)
.switch("header-row", "treat the first row as column names")
.switch("ignore-titles", "don't pivot the column names into values")
.rest(
SyntaxShape::String,
"the names to give columns once pivoted",
)
}

fn usage(&self) -> &str {
Expand Down