2022-01-24 16:05:19 +01:00
|
|
|
use nu_protocol::{
|
|
|
|
ast::Call,
|
|
|
|
engine::{EngineState, Stack},
|
2022-06-05 15:13:04 +02:00
|
|
|
Example, IntoPipelineData, Signature, Span, SyntaxShape, Value,
|
2022-01-24 16:05:19 +01:00
|
|
|
};
|
2022-06-04 08:47:36 +02:00
|
|
|
use std::fmt::Write;
|
2022-03-27 21:25:30 +02:00
|
|
|
|
2022-04-21 13:13:58 +02:00
|
|
|
pub fn get_full_help(
|
|
|
|
sig: &Signature,
|
|
|
|
examples: &[Example],
|
|
|
|
engine_state: &EngineState,
|
|
|
|
stack: &mut Stack,
|
2022-11-20 14:22:42 +01:00
|
|
|
is_parser_keyword: bool,
|
2022-04-21 13:13:58 +02:00
|
|
|
) -> String {
|
2022-08-31 10:15:03 +02:00
|
|
|
let config = engine_state.get_config();
|
|
|
|
let doc_config = DocumentationConfig {
|
|
|
|
no_subcommands: false,
|
|
|
|
no_color: !config.use_ansi_coloring,
|
|
|
|
brief: false,
|
|
|
|
};
|
2022-11-20 14:22:42 +01:00
|
|
|
get_documentation(
|
|
|
|
sig,
|
|
|
|
examples,
|
|
|
|
engine_state,
|
|
|
|
stack,
|
|
|
|
&doc_config,
|
|
|
|
is_parser_keyword,
|
|
|
|
)
|
2022-04-21 13:13:58 +02:00
|
|
|
}
|
2020-07-18 00:22:43 +02:00
|
|
|
|
2021-12-02 19:05:38 +01:00
|
|
|
#[derive(Default)]
|
2022-04-21 13:13:58 +02:00
|
|
|
struct DocumentationConfig {
|
2020-07-18 00:22:43 +02:00
|
|
|
no_subcommands: bool,
|
2021-02-22 19:33:34 +01:00
|
|
|
no_color: bool,
|
2021-03-08 00:57:58 +01:00
|
|
|
brief: bool,
|
2020-07-18 00:22:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::cognitive_complexity)]
|
2022-04-21 13:13:58 +02:00
|
|
|
fn get_documentation(
|
2021-10-09 03:02:01 +02:00
|
|
|
sig: &Signature,
|
|
|
|
examples: &[Example],
|
2021-10-25 08:31:39 +02:00
|
|
|
engine_state: &EngineState,
|
2022-01-24 16:05:19 +01:00
|
|
|
stack: &mut Stack,
|
2021-10-09 03:02:01 +02:00
|
|
|
config: &DocumentationConfig,
|
2022-11-20 14:22:42 +01:00
|
|
|
is_parser_keyword: bool,
|
2021-10-09 03:02:01 +02:00
|
|
|
) -> String {
|
2022-08-31 10:15:03 +02:00
|
|
|
// Create ansi colors
|
|
|
|
const G: &str = "\x1b[32m"; // green
|
|
|
|
const C: &str = "\x1b[36m"; // cyan
|
|
|
|
const BB: &str = "\x1b[1;34m"; // bold blue
|
|
|
|
const RESET: &str = "\x1b[0m"; // reset
|
|
|
|
|
2021-10-09 03:02:01 +02:00
|
|
|
let cmd_name = &sig.name;
|
|
|
|
let mut long_desc = String::new();
|
|
|
|
|
|
|
|
let usage = &sig.usage;
|
2021-01-12 19:27:48 +01:00
|
|
|
if !usage.is_empty() {
|
|
|
|
long_desc.push_str(usage);
|
|
|
|
long_desc.push_str("\n\n");
|
|
|
|
}
|
2020-07-18 00:22:43 +02:00
|
|
|
|
2021-10-09 03:02:01 +02:00
|
|
|
let extra_usage = if config.brief { "" } else { &sig.extra_usage };
|
2021-03-08 00:57:58 +01:00
|
|
|
if !extra_usage.is_empty() {
|
|
|
|
long_desc.push_str(extra_usage);
|
|
|
|
long_desc.push_str("\n\n");
|
|
|
|
}
|
|
|
|
|
2020-08-23 22:35:16 +02:00
|
|
|
let mut subcommands = vec![];
|
2020-07-18 00:22:43 +02:00
|
|
|
if !config.no_subcommands {
|
2021-12-03 19:45:29 +01:00
|
|
|
let signatures = engine_state.get_signatures(true);
|
2021-10-09 03:02:01 +02:00
|
|
|
for sig in signatures {
|
|
|
|
if sig.name.starts_with(&format!("{} ", cmd_name)) {
|
2022-08-31 10:15:03 +02:00
|
|
|
subcommands.push(format!(" {C}{}{RESET} - {}", sig.name, sig.usage));
|
2020-07-18 00:22:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-27 21:25:30 +02:00
|
|
|
if !sig.search_terms.is_empty() {
|
2022-08-31 10:15:03 +02:00
|
|
|
let text = format!(
|
|
|
|
"{G}Search terms{RESET}: {C}{}{}\n\n",
|
|
|
|
sig.search_terms.join(", "),
|
|
|
|
RESET
|
2022-06-04 08:47:36 +02:00
|
|
|
);
|
2022-08-31 10:15:03 +02:00
|
|
|
let _ = write!(long_desc, "{}", text);
|
2022-03-27 21:25:30 +02:00
|
|
|
}
|
|
|
|
|
2022-08-31 10:15:03 +02:00
|
|
|
let text = format!("{}Usage{}:\n > {}\n", G, RESET, sig.call_signature());
|
|
|
|
let _ = write!(long_desc, "{}", text);
|
2020-07-18 00:22:43 +02:00
|
|
|
|
|
|
|
if !subcommands.is_empty() {
|
Apply clippy fix for rust 1.63.0 (#6576)
* Apply clippy fix to avoid extra allocation
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:82:9
|
82 | long_desc.push_str(&format!("\n{G}Subcommands{RESET}:\n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::format-push-string` implied by `-D warnings`
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:96:9
|
96 | long_desc.push_str(&format!("\n{G}Parameters{RESET}:\n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:128:9
|
128 | long_desc.push_str(&format!("\n{}Examples{}:", G, RESET));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:202:5
|
202 | long_desc.push_str(&format!("\n{}Flags{}:\n", G, RESET));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: could not compile `nu-engine` due to 4 previous errors
* Apply clippy fix to avoid deref on an immutable reference
error: deref on an immutable reference
--> crates/nu-command/src/dataframe/eager/sql_context.rs:188:77
|
188 | SetExpr::Select(select_stmt) => self.execute_select(&*select_stmt)?,
| ^^^^^^^^^^^^^
|
= note: `-D clippy::borrow-deref-ref` implied by `-D warnings`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
help: if you would like to reborrow, try removing `&*`
|
188 | SetExpr::Select(select_stmt) => self.execute_select(select_stmt)?,
| ~~~~~~~~~~~
help: if you would like to deref, try using `&**`
|
188 | SetExpr::Select(select_stmt) => self.execute_select(&**select_stmt)?,
| ~~~~~~~~~~~~~~
error: deref on an immutable reference
--> crates/nu-command/src/database/values/dsl/expression.rs:252:15
|
252 | match &*expr {
| ^^^^^^ help: if you would like to reborrow, try removing `&*`: `expr`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
error: could not compile `nu-command` due to 2 previous errors
2022-09-17 19:10:32 +02:00
|
|
|
let _ = write!(long_desc, "\n{G}Subcommands{RESET}:\n");
|
2020-08-23 22:35:16 +02:00
|
|
|
subcommands.sort();
|
|
|
|
long_desc.push_str(&subcommands.join("\n"));
|
2020-11-22 01:37:16 +01:00
|
|
|
long_desc.push('\n');
|
2020-07-18 00:22:43 +02:00
|
|
|
}
|
|
|
|
|
2022-01-26 15:42:39 +01:00
|
|
|
if !sig.named.is_empty() {
|
|
|
|
long_desc.push_str(&get_flags_section(sig))
|
|
|
|
}
|
|
|
|
|
2022-11-20 14:22:42 +01:00
|
|
|
if !is_parser_keyword && !sig.input_output_types.is_empty() {
|
|
|
|
if sig.operates_on_cell_paths() {
|
|
|
|
let _ = writeln!(
|
|
|
|
long_desc,
|
|
|
|
"\n{}Signatures(Cell paths are supported){}:\n{}",
|
|
|
|
G, RESET, sig
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
let _ = writeln!(long_desc, "\n{}Signatures{}:\n{}", G, RESET, sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-09 03:02:01 +02:00
|
|
|
if !sig.required_positional.is_empty()
|
|
|
|
|| !sig.optional_positional.is_empty()
|
|
|
|
|| sig.rest_positional.is_some()
|
|
|
|
{
|
Apply clippy fix for rust 1.63.0 (#6576)
* Apply clippy fix to avoid extra allocation
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:82:9
|
82 | long_desc.push_str(&format!("\n{G}Subcommands{RESET}:\n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::format-push-string` implied by `-D warnings`
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:96:9
|
96 | long_desc.push_str(&format!("\n{G}Parameters{RESET}:\n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:128:9
|
128 | long_desc.push_str(&format!("\n{}Examples{}:", G, RESET));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:202:5
|
202 | long_desc.push_str(&format!("\n{}Flags{}:\n", G, RESET));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: could not compile `nu-engine` due to 4 previous errors
* Apply clippy fix to avoid deref on an immutable reference
error: deref on an immutable reference
--> crates/nu-command/src/dataframe/eager/sql_context.rs:188:77
|
188 | SetExpr::Select(select_stmt) => self.execute_select(&*select_stmt)?,
| ^^^^^^^^^^^^^
|
= note: `-D clippy::borrow-deref-ref` implied by `-D warnings`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
help: if you would like to reborrow, try removing `&*`
|
188 | SetExpr::Select(select_stmt) => self.execute_select(select_stmt)?,
| ~~~~~~~~~~~
help: if you would like to deref, try using `&**`
|
188 | SetExpr::Select(select_stmt) => self.execute_select(&**select_stmt)?,
| ~~~~~~~~~~~~~~
error: deref on an immutable reference
--> crates/nu-command/src/database/values/dsl/expression.rs:252:15
|
252 | match &*expr {
| ^^^^^^ help: if you would like to reborrow, try removing `&*`: `expr`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
error: could not compile `nu-command` due to 2 previous errors
2022-09-17 19:10:32 +02:00
|
|
|
let _ = write!(long_desc, "\n{G}Parameters{RESET}:\n");
|
2021-10-09 03:02:01 +02:00
|
|
|
for positional in &sig.required_positional {
|
2022-11-26 08:16:39 +01:00
|
|
|
let text = match &positional.shape {
|
|
|
|
SyntaxShape::Keyword(kw, shape) => {
|
|
|
|
format!(
|
|
|
|
" {C}\"{}\" + {RESET}<{BB}{}{RESET}>: {}",
|
|
|
|
String::from_utf8_lossy(kw),
|
|
|
|
document_shape(*shape.clone()),
|
|
|
|
positional.desc
|
|
|
|
)
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
format!(
|
|
|
|
" {C}{}{RESET} <{BB}{}{RESET}>: {}",
|
|
|
|
positional.name,
|
|
|
|
document_shape(positional.shape.clone()),
|
|
|
|
positional.desc
|
|
|
|
)
|
|
|
|
}
|
|
|
|
};
|
2022-08-31 10:15:03 +02:00
|
|
|
let _ = writeln!(long_desc, "{}", text);
|
2021-10-09 03:02:01 +02:00
|
|
|
}
|
|
|
|
for positional in &sig.optional_positional {
|
2022-11-26 08:16:39 +01:00
|
|
|
let text = match &positional.shape {
|
|
|
|
SyntaxShape::Keyword(kw, shape) => {
|
|
|
|
format!(
|
|
|
|
" (optional) {C}\"{}\" + {RESET}<{BB}{}{RESET}>: {}",
|
|
|
|
String::from_utf8_lossy(kw),
|
|
|
|
document_shape(*shape.clone()),
|
|
|
|
positional.desc
|
|
|
|
)
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
format!(
|
|
|
|
" (optional) {C}{}{RESET} <{BB}{}{RESET}>: {}",
|
|
|
|
positional.name,
|
|
|
|
document_shape(positional.shape.clone()),
|
|
|
|
positional.desc
|
|
|
|
)
|
|
|
|
}
|
|
|
|
};
|
2022-08-31 10:15:03 +02:00
|
|
|
let _ = writeln!(long_desc, "{}", text);
|
2021-10-09 03:02:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(rest_positional) = &sig.rest_positional {
|
2022-08-31 10:15:03 +02:00
|
|
|
let text = format!(
|
2022-11-26 08:16:39 +01:00
|
|
|
" ...{C}{}{RESET} <{BB}{}{RESET}>: {}",
|
2022-06-05 15:13:04 +02:00
|
|
|
rest_positional.name,
|
|
|
|
document_shape(rest_positional.shape.clone()),
|
|
|
|
rest_positional.desc
|
2022-06-04 08:47:36 +02:00
|
|
|
);
|
2022-08-31 10:15:03 +02:00
|
|
|
let _ = writeln!(long_desc, "{}", text);
|
2021-10-09 03:02:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !examples.is_empty() {
|
Apply clippy fix for rust 1.63.0 (#6576)
* Apply clippy fix to avoid extra allocation
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:82:9
|
82 | long_desc.push_str(&format!("\n{G}Subcommands{RESET}:\n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::format-push-string` implied by `-D warnings`
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:96:9
|
96 | long_desc.push_str(&format!("\n{G}Parameters{RESET}:\n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:128:9
|
128 | long_desc.push_str(&format!("\n{}Examples{}:", G, RESET));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:202:5
|
202 | long_desc.push_str(&format!("\n{}Flags{}:\n", G, RESET));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: could not compile `nu-engine` due to 4 previous errors
* Apply clippy fix to avoid deref on an immutable reference
error: deref on an immutable reference
--> crates/nu-command/src/dataframe/eager/sql_context.rs:188:77
|
188 | SetExpr::Select(select_stmt) => self.execute_select(&*select_stmt)?,
| ^^^^^^^^^^^^^
|
= note: `-D clippy::borrow-deref-ref` implied by `-D warnings`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
help: if you would like to reborrow, try removing `&*`
|
188 | SetExpr::Select(select_stmt) => self.execute_select(select_stmt)?,
| ~~~~~~~~~~~
help: if you would like to deref, try using `&**`
|
188 | SetExpr::Select(select_stmt) => self.execute_select(&**select_stmt)?,
| ~~~~~~~~~~~~~~
error: deref on an immutable reference
--> crates/nu-command/src/database/values/dsl/expression.rs:252:15
|
252 | match &*expr {
| ^^^^^^ help: if you would like to reborrow, try removing `&*`: `expr`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
error: could not compile `nu-command` due to 2 previous errors
2022-09-17 19:10:32 +02:00
|
|
|
let _ = write!(long_desc, "\n{}Examples{}:", G, RESET);
|
2021-10-09 03:02:01 +02:00
|
|
|
}
|
2022-01-26 15:42:39 +01:00
|
|
|
|
2020-07-18 00:22:43 +02:00
|
|
|
for example in examples {
|
2020-11-22 01:37:16 +01:00
|
|
|
long_desc.push('\n');
|
2020-07-18 00:22:43 +02:00
|
|
|
long_desc.push_str(" ");
|
|
|
|
long_desc.push_str(example.description);
|
|
|
|
|
2021-02-22 19:33:34 +01:00
|
|
|
if config.no_color {
|
2022-06-04 08:47:36 +02:00
|
|
|
let _ = write!(long_desc, "\n > {}\n", example.example);
|
2022-05-07 21:39:22 +02:00
|
|
|
} else if let Some(highlighter) = engine_state.find_decl(b"nu-highlight", &[]) {
|
2022-01-24 16:05:19 +01:00
|
|
|
let decl = engine_state.get_decl(highlighter);
|
2021-10-09 03:02:01 +02:00
|
|
|
|
2022-01-26 15:42:39 +01:00
|
|
|
match decl.run(
|
2022-01-24 16:05:19 +01:00
|
|
|
engine_state,
|
|
|
|
stack,
|
2022-12-03 10:44:12 +01:00
|
|
|
&Call::new(Span::unknown()),
|
2022-01-24 16:05:19 +01:00
|
|
|
Value::String {
|
|
|
|
val: example.example.to_string(),
|
2022-12-03 10:44:12 +01:00
|
|
|
span: Span::unknown(),
|
2022-01-24 16:05:19 +01:00
|
|
|
}
|
|
|
|
.into_pipeline_data(),
|
|
|
|
) {
|
2022-01-26 15:42:39 +01:00
|
|
|
Ok(output) => {
|
2022-12-03 10:44:12 +01:00
|
|
|
let result = output.into_value(Span::unknown());
|
2022-01-26 15:42:39 +01:00
|
|
|
match result.as_string() {
|
|
|
|
Ok(s) => {
|
2022-06-04 08:47:36 +02:00
|
|
|
let _ = write!(long_desc, "\n > {}\n", s);
|
2022-01-26 15:42:39 +01:00
|
|
|
}
|
|
|
|
_ => {
|
2022-06-04 08:47:36 +02:00
|
|
|
let _ = write!(long_desc, "\n > {}\n", example.example);
|
2022-01-26 15:42:39 +01:00
|
|
|
}
|
2022-01-24 16:05:19 +01:00
|
|
|
}
|
|
|
|
}
|
2022-01-26 15:42:39 +01:00
|
|
|
Err(_) => {
|
2022-06-04 08:47:36 +02:00
|
|
|
let _ = write!(long_desc, "\n > {}\n", example.example);
|
2022-01-26 15:42:39 +01:00
|
|
|
}
|
2022-01-24 16:05:19 +01:00
|
|
|
}
|
2022-01-26 15:42:39 +01:00
|
|
|
} else {
|
2022-06-04 08:47:36 +02:00
|
|
|
let _ = write!(long_desc, "\n > {}\n", example.example);
|
2020-07-18 00:22:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-22 01:37:16 +01:00
|
|
|
long_desc.push('\n');
|
2020-07-18 00:22:43 +02:00
|
|
|
|
2022-11-04 19:49:45 +01:00
|
|
|
if config.no_color {
|
|
|
|
nu_utils::strip_ansi_string_likely(long_desc)
|
2022-08-31 10:15:03 +02:00
|
|
|
} else {
|
|
|
|
long_desc
|
2022-11-04 19:49:45 +01:00
|
|
|
}
|
2020-07-18 00:22:43 +02:00
|
|
|
}
|
|
|
|
|
2022-06-05 15:13:04 +02:00
|
|
|
// document shape helps showing more useful information
|
|
|
|
pub fn document_shape(shape: SyntaxShape) -> SyntaxShape {
|
|
|
|
match shape {
|
|
|
|
SyntaxShape::Custom(inner_shape, _) => *inner_shape,
|
|
|
|
_ => shape,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-01 19:45:48 +01:00
|
|
|
pub fn get_flags_section(signature: &Signature) -> String {
|
2022-08-31 10:15:03 +02:00
|
|
|
const G: &str = "\x1b[32m"; // green
|
|
|
|
const C: &str = "\x1b[36m"; // cyan
|
|
|
|
const BB: &str = "\x1b[1;34m"; // bold blue
|
|
|
|
const RESET: &str = "\x1b[0m"; // reset
|
|
|
|
const D: &str = "\x1b[39m"; // default
|
|
|
|
|
2021-10-09 03:02:01 +02:00
|
|
|
let mut long_desc = String::new();
|
Apply clippy fix for rust 1.63.0 (#6576)
* Apply clippy fix to avoid extra allocation
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:82:9
|
82 | long_desc.push_str(&format!("\n{G}Subcommands{RESET}:\n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::format-push-string` implied by `-D warnings`
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:96:9
|
96 | long_desc.push_str(&format!("\n{G}Parameters{RESET}:\n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:128:9
|
128 | long_desc.push_str(&format!("\n{}Examples{}:", G, RESET));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:202:5
|
202 | long_desc.push_str(&format!("\n{}Flags{}:\n", G, RESET));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: could not compile `nu-engine` due to 4 previous errors
* Apply clippy fix to avoid deref on an immutable reference
error: deref on an immutable reference
--> crates/nu-command/src/dataframe/eager/sql_context.rs:188:77
|
188 | SetExpr::Select(select_stmt) => self.execute_select(&*select_stmt)?,
| ^^^^^^^^^^^^^
|
= note: `-D clippy::borrow-deref-ref` implied by `-D warnings`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
help: if you would like to reborrow, try removing `&*`
|
188 | SetExpr::Select(select_stmt) => self.execute_select(select_stmt)?,
| ~~~~~~~~~~~
help: if you would like to deref, try using `&**`
|
188 | SetExpr::Select(select_stmt) => self.execute_select(&**select_stmt)?,
| ~~~~~~~~~~~~~~
error: deref on an immutable reference
--> crates/nu-command/src/database/values/dsl/expression.rs:252:15
|
252 | match &*expr {
| ^^^^^^ help: if you would like to reborrow, try removing `&*`: `expr`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
error: could not compile `nu-command` due to 2 previous errors
2022-09-17 19:10:32 +02:00
|
|
|
let _ = write!(long_desc, "\n{}Flags{}:\n", G, RESET);
|
2021-10-09 03:02:01 +02:00
|
|
|
for flag in &signature.named {
|
|
|
|
let msg = if let Some(arg) = &flag.arg {
|
|
|
|
if let Some(short) = flag.short {
|
|
|
|
if flag.required {
|
|
|
|
format!(
|
2022-08-31 10:15:03 +02:00
|
|
|
" {C}-{}{}{RESET} (required parameter) {:?} - {}\n",
|
2021-10-13 19:58:39 +02:00
|
|
|
short,
|
|
|
|
if !flag.long.is_empty() {
|
2022-08-31 10:15:03 +02:00
|
|
|
format!("{D},{RESET} {C}--{}", flag.long)
|
2021-10-13 19:58:39 +02:00
|
|
|
} else {
|
|
|
|
"".into()
|
|
|
|
},
|
|
|
|
arg,
|
|
|
|
flag.desc
|
2021-10-09 03:02:01 +02:00
|
|
|
)
|
|
|
|
} else {
|
2021-10-13 19:58:39 +02:00
|
|
|
format!(
|
2022-08-31 10:15:03 +02:00
|
|
|
" {C}-{}{}{RESET} <{BB}{:?}{RESET}> - {}\n",
|
2021-10-13 19:58:39 +02:00
|
|
|
short,
|
|
|
|
if !flag.long.is_empty() {
|
2022-08-31 10:15:03 +02:00
|
|
|
format!("{D},{RESET} {C}--{}", flag.long)
|
2021-10-13 19:58:39 +02:00
|
|
|
} else {
|
|
|
|
"".into()
|
|
|
|
},
|
|
|
|
arg,
|
|
|
|
flag.desc
|
|
|
|
)
|
2021-10-09 03:02:01 +02:00
|
|
|
}
|
|
|
|
} else if flag.required {
|
|
|
|
format!(
|
2022-08-31 10:15:03 +02:00
|
|
|
" {C}--{}{RESET} (required parameter) <{BB}{:?}{RESET}> - {}\n",
|
2021-10-09 03:02:01 +02:00
|
|
|
flag.long, arg, flag.desc
|
|
|
|
)
|
|
|
|
} else {
|
2022-08-31 10:15:03 +02:00
|
|
|
format!(
|
|
|
|
" {C}--{}{RESET} <{BB}{:?}{RESET}> - {}\n",
|
|
|
|
flag.long, arg, flag.desc
|
|
|
|
)
|
2021-10-09 03:02:01 +02:00
|
|
|
}
|
|
|
|
} else if let Some(short) = flag.short {
|
|
|
|
if flag.required {
|
|
|
|
format!(
|
2022-08-31 10:15:03 +02:00
|
|
|
" {C}-{}{}{RESET} (required parameter) - {}\n",
|
2021-10-13 19:58:39 +02:00
|
|
|
short,
|
|
|
|
if !flag.long.is_empty() {
|
2022-08-31 10:15:03 +02:00
|
|
|
format!("{D},{RESET} {C}--{}", flag.long)
|
2021-10-13 19:58:39 +02:00
|
|
|
} else {
|
|
|
|
"".into()
|
|
|
|
},
|
|
|
|
flag.desc
|
2021-10-09 03:02:01 +02:00
|
|
|
)
|
|
|
|
} else {
|
2021-10-13 19:58:39 +02:00
|
|
|
format!(
|
2022-08-31 10:15:03 +02:00
|
|
|
" {C}-{}{}{RESET} - {}\n",
|
2021-10-13 19:58:39 +02:00
|
|
|
short,
|
|
|
|
if !flag.long.is_empty() {
|
2022-08-31 10:15:03 +02:00
|
|
|
format!("{D},{RESET} {C}--{}", flag.long)
|
2021-10-13 19:58:39 +02:00
|
|
|
} else {
|
|
|
|
"".into()
|
|
|
|
},
|
|
|
|
flag.desc
|
|
|
|
)
|
2021-10-09 03:02:01 +02:00
|
|
|
}
|
|
|
|
} else if flag.required {
|
2022-01-26 18:26:43 +01:00
|
|
|
format!(
|
2022-08-31 10:15:03 +02:00
|
|
|
" {C}--{}{RESET} (required parameter) - {}\n",
|
2022-01-26 18:26:43 +01:00
|
|
|
flag.long, flag.desc
|
|
|
|
)
|
2021-10-09 03:02:01 +02:00
|
|
|
} else {
|
2022-08-31 10:15:03 +02:00
|
|
|
format!(" {C}--{}{RESET} - {}\n", flag.long, flag.desc)
|
2020-07-18 00:22:43 +02:00
|
|
|
};
|
|
|
|
long_desc.push_str(&msg);
|
|
|
|
}
|
|
|
|
long_desc
|
|
|
|
}
|