Category option for signature (#343)

* category option for signature

* category option for signature

* column description for $scope
This commit is contained in:
Fernando Herrera
2021-11-17 04:22:37 +00:00
committed by GitHub
parent 6fbe02eb21
commit b35914bd17
118 changed files with 739 additions and 335 deletions

View File

@ -2,7 +2,8 @@ use nu_engine::eval_expression;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape,
Value,
};
#[derive(Clone)]
@ -18,7 +19,9 @@ impl Command for BuildString {
}
fn signature(&self) -> nu_protocol::Signature {
Signature::build("build-string").rest("rest", SyntaxShape::String, "list of string")
Signature::build("build-string")
.rest("rest", SyntaxShape::String, "list of string")
.category(Category::Strings)
}
fn examples(&self) -> Vec<Example> {

View File

@ -2,7 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::{Call, PathMember};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, ValueStream,
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, ValueStream,
};
#[derive(Clone)]
@ -14,11 +14,13 @@ impl Command for Format {
}
fn signature(&self) -> Signature {
Signature::build("format").required(
"pattern",
SyntaxShape::String,
"the pattern to output. e.g.) \"{foo}: {bar}\"",
)
Signature::build("format")
.required(
"pattern",
SyntaxShape::String,
"the pattern to output. e.g.) \"{foo}: {bar}\"",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,8 +2,8 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
ValueStream,
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type,
Value, ValueStream,
};
use regex::Regex;
@ -27,6 +27,7 @@ impl Command for Parse {
"the pattern to match. Eg) \"{foo}: {bar}\"",
)
.switch("regex", "use full regex syntax for patterns", Some('r'))
.category(Category::Strings)
}
fn examples(&self) -> Vec<Example> {

View File

@ -4,7 +4,7 @@ use unicode_segmentation::UnicodeSegmentation;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Type, Value};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Span, Type, Value};
#[derive(Clone)]
pub struct Size;
@ -15,7 +15,7 @@ impl Command for Size {
}
fn signature(&self) -> Signature {
Signature::build("size")
Signature::build("size").category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -1,7 +1,7 @@
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Example, PipelineData, ShellError, Signature, Span, Type, Value,
Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
};
#[derive(Clone)]
@ -13,7 +13,7 @@ impl Command for SubCommand {
}
fn signature(&self) -> Signature {
Signature::build("split chars")
Signature::build("split chars").category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,7 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
Category, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
};
#[derive(Clone)]
@ -26,6 +26,7 @@ impl Command for SubCommand {
SyntaxShape::String,
"column names to give the new columns",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
IntoPipelineData, PipelineData, Signature, Value,
Category, IntoPipelineData, PipelineData, Signature, Value,
};
#[derive(Clone)]
@ -14,7 +14,7 @@ impl Command for SplitCommand {
}
fn signature(&self) -> Signature {
Signature::build("split")
Signature::build("split").category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,7 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
Category, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
};
#[derive(Clone)]
@ -14,11 +14,13 @@ impl Command for SubCommand {
}
fn signature(&self) -> Signature {
Signature::build("split row").required(
"separator",
SyntaxShape::String,
"the character that denotes what separates rows",
)
Signature::build("split row")
.required(
"separator",
SyntaxShape::String,
"the character that denotes what separates rows",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,6 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::ast::CellPath;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::Category;
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
#[derive(Clone)]
@ -13,11 +14,13 @@ impl Command for SubCommand {
}
fn signature(&self) -> Signature {
Signature::build("str capitalize").rest(
"rest",
SyntaxShape::CellPath,
"optionally capitalize text by column paths",
)
Signature::build("str capitalize")
.rest(
"rest",
SyntaxShape::CellPath,
"optionally capitalize text by column paths",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -1,7 +1,9 @@
use inflector::cases::camelcase::to_camel_case;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
use crate::operate;
@ -14,11 +16,13 @@ impl Command for SubCommand {
}
fn signature(&self) -> Signature {
Signature::build("str camel-case").rest(
"rest",
SyntaxShape::CellPath,
"optionally convert text to camelCase by column paths",
)
Signature::build("str camel-case")
.rest(
"rest",
SyntaxShape::CellPath,
"optionally convert text to camelCase by column paths",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
IntoPipelineData, PipelineData, Signature, Value,
Category, IntoPipelineData, PipelineData, Signature, Value,
};
#[derive(Clone)]
@ -14,7 +14,7 @@ impl Command for Str {
}
fn signature(&self) -> Signature {
Signature::build("str")
Signature::build("str").category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -1,7 +1,9 @@
use inflector::cases::kebabcase::to_kebab_case;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
use crate::operate;
@ -14,11 +16,13 @@ impl Command for SubCommand {
}
fn signature(&self) -> Signature {
Signature::build("str kebab-case").rest(
"rest",
SyntaxShape::CellPath,
"optionally convert text to kebab-case by column paths",
)
Signature::build("str kebab-case")
.rest(
"rest",
SyntaxShape::CellPath,
"optionally convert text to kebab-case by column paths",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -1,7 +1,9 @@
use inflector::cases::pascalcase::to_pascal_case;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
use crate::operate;
@ -14,11 +16,13 @@ impl Command for SubCommand {
}
fn signature(&self) -> Signature {
Signature::build("str pascal-case").rest(
"rest",
SyntaxShape::CellPath,
"optionally convert text to PascalCase by column paths",
)
Signature::build("str pascal-case")
.rest(
"rest",
SyntaxShape::CellPath,
"optionally convert text to PascalCase by column paths",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -1,7 +1,9 @@
use inflector::cases::screamingsnakecase::to_screaming_snake_case;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
use crate::operate;
#[derive(Clone)]
@ -13,11 +15,13 @@ impl Command for SubCommand {
}
fn signature(&self) -> Signature {
Signature::build("str screaming-snake-case").rest(
"rest",
SyntaxShape::CellPath,
"optionally convert text to SCREAMING_SNAKE_CASE by column paths",
)
Signature::build("str screaming-snake-case")
.rest(
"rest",
SyntaxShape::CellPath,
"optionally convert text to SCREAMING_SNAKE_CASE by column paths",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -1,7 +1,9 @@
use inflector::cases::snakecase::to_snake_case;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
use crate::operate;
#[derive(Clone)]
@ -13,11 +15,13 @@ impl Command for SubCommand {
}
fn signature(&self) -> Signature {
Signature::build("str snake-case").rest(
"rest",
SyntaxShape::CellPath,
"optionally convert text to snake_case by column paths",
)
Signature::build("str snake-case")
.rest(
"rest",
SyntaxShape::CellPath,
"optionally convert text to snake_case by column paths",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {
"converts a string to snake_case"

View File

@ -2,7 +2,8 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape,
Value,
};
#[derive(Clone)]
@ -14,11 +15,13 @@ impl Command for StrCollect {
}
fn signature(&self) -> Signature {
Signature::build("str collect").optional(
"separator",
SyntaxShape::String,
"optional separator to use when creating string",
)
Signature::build("str collect")
.optional(
"separator",
SyntaxShape::String,
"optional separator to use when creating string",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,6 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::ast::CellPath;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::Category;
use nu_protocol::{
Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value,
};
@ -23,6 +24,7 @@ impl Command for SubCommand {
"optionally check if string contains pattern by column paths",
)
.switch("insensitive", "search is case insensitive", Some('i'))
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,6 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::ast::CellPath;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::Category;
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
#[derive(Clone)]
@ -13,11 +14,13 @@ impl Command for SubCommand {
}
fn signature(&self) -> Signature {
Signature::build("str downcase").rest(
"rest",
SyntaxShape::CellPath,
"optionally downcase text by column paths",
)
Signature::build("str downcase")
.rest(
"rest",
SyntaxShape::CellPath,
"optionally downcase text by column paths",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,6 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::ast::CellPath;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::Category;
use nu_protocol::Spanned;
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
@ -21,6 +22,7 @@ impl Command for SubCommand {
SyntaxShape::CellPath,
"optionally matches suffix of text by column paths",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,6 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::ast::CellPath;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::Category;
use nu_protocol::Spanned;
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
use regex::Regex;
@ -32,6 +33,7 @@ impl Command for SubCommand {
"optionally find and replace text by column paths",
)
.switch("all", "replace all occurrences of find string", Some('a'))
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,6 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::ast::CellPath;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::Category;
use nu_protocol::Spanned;
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
use std::sync::Arc;
@ -43,6 +44,7 @@ impl Command for SubCommand {
Some('r'),
)
.switch("end", "search from the end of the string", Some('e'))
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,6 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::ast::CellPath;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::Category;
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
#[derive(Clone)]
@ -13,11 +14,13 @@ impl Command for SubCommand {
}
fn signature(&self) -> Signature {
Signature::build("str length").rest(
"rest",
SyntaxShape::CellPath,
"optionally find length of text by column paths",
)
Signature::build("str length")
.rest(
"rest",
SyntaxShape::CellPath,
"optionally find length of text by column paths",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,6 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::ast::CellPath;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::Category;
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
use std::sync::Arc;
@ -33,11 +34,13 @@ impl Command for SubCommand {
SyntaxShape::CellPath,
"optionally check if string contains pattern by column paths",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {
"pad a string with a character a certain length"
}
fn run(
&self,
engine_state: &EngineState,

View File

@ -2,6 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::ast::CellPath;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::Category;
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
#[derive(Clone)]
@ -13,11 +14,13 @@ impl Command for SubCommand {
}
fn signature(&self) -> Signature {
Signature::build("str reverse").rest(
"rest",
SyntaxShape::CellPath,
"optionally reverse text by column paths",
)
Signature::build("str reverse")
.rest(
"rest",
SyntaxShape::CellPath,
"optionally reverse text by column paths",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,6 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::ast::CellPath;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::Category;
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
use std::sync::Arc;
@ -33,6 +34,7 @@ impl Command for SubCommand {
SyntaxShape::CellPath,
"optionally check if string contains pattern by column paths",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {

View File

@ -2,6 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::ast::CellPath;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::Category;
use nu_protocol::Spanned;
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value};
use std::sync::Arc;
@ -28,6 +29,7 @@ impl Command for SubCommand {
SyntaxShape::CellPath,
"optionally matches prefix of text by column paths",
)
.category(Category::Strings)
}
fn usage(&self) -> &str {