From 2ba12afb01547b545e3a760c5bffc84c2db46d38 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Sun, 20 Feb 2022 15:20:41 -0500 Subject: [PATCH] A few fixes to docs generation and default config (#4570) * A few fixes to docs generation and default config * A few more fixes --- crates/nu-engine/src/eval.rs | 6 ++ crates/nu-protocol/src/config.rs | 4 +- crates/nu-protocol/src/shell_error.rs | 4 + crates/nu-protocol/src/value/from_value.rs | 88 ++++++++++++++++------ docs/commands/git_checkout.md | 16 ---- docs/commands/git_push.md | 17 ----- docs/commands/post.md | 8 +- docs/make_docs.nu | 3 +- src/default_config.nu | 4 +- 9 files changed, 88 insertions(+), 62 deletions(-) delete mode 100644 docs/commands/git_checkout.md delete mode 100644 docs/commands/git_push.md diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index b16d934ed8..361ff6eef4 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -937,6 +937,12 @@ pub fn eval_variable( span, }); + cols.push("is_extern".to_string()); + vals.push(Value::Bool { + val: decl.is_known_external(), + span, + }); + cols.push("creates_scope".to_string()); vals.push(Value::Bool { val: signature.creates_scope, diff --git a/crates/nu-protocol/src/config.rs b/crates/nu-protocol/src/config.rs index effc1a3c29..98fb1c6e61 100644 --- a/crates/nu-protocol/src/config.rs +++ b/crates/nu-protocol/src/config.rs @@ -43,12 +43,12 @@ impl Default for Config { use_ls_colors: true, color_config: HashMap::new(), use_grid_icons: false, - footer_mode: FooterMode::Never, + footer_mode: FooterMode::RowCount(25), animate_prompt: ANIMATE_PROMPT_DEFAULT, float_precision: 4, filesize_format: "auto".into(), use_ansi_coloring: true, - quick_completions: false, + quick_completions: true, edit_mode: "emacs".into(), max_history_size: 1000, log_level: String::new(), diff --git a/crates/nu-protocol/src/shell_error.rs b/crates/nu-protocol/src/shell_error.rs index 6eade6e685..513a230ac6 100644 --- a/crates/nu-protocol/src/shell_error.rs +++ b/crates/nu-protocol/src/shell_error.rs @@ -256,6 +256,10 @@ pub enum ShellError { #[diagnostic(code(nu::shell::missing_config_value), url(docsrs))] MissingConfigValue(String, #[label = "missing {0}"] Span), + #[error("Negative value passed when positive one is required")] + #[diagnostic(code(nu::shell::needs_positive_value), url(docsrs))] + NeedsPositiveValue(#[label = "use a positive value"] Span), + #[error("{0}")] #[diagnostic()] SpannedLabeledError(String, String, #[label("{1}")] Span), diff --git a/crates/nu-protocol/src/value/from_value.rs b/crates/nu-protocol/src/value/from_value.rs index e96bc88044..019f0453c2 100644 --- a/crates/nu-protocol/src/value/from_value.rs +++ b/crates/nu-protocol/src/value/from_value.rs @@ -96,21 +96,39 @@ impl FromValue for f64 { impl FromValue for Spanned { fn from_value(v: &Value) -> Result { match v { - Value::Int { val, span } => Ok(Spanned { - item: *val as usize, - span: *span, - }), - Value::Filesize { val, span } => Ok(Spanned { - item: *val as usize, - span: *span, - }), - Value::Duration { val, span } => Ok(Spanned { - item: *val as usize, - span: *span, - }), + Value::Int { val, span } => { + if val.is_negative() { + Err(ShellError::NeedsPositiveValue(*span)) + } else { + Ok(Spanned { + item: *val as usize, + span: *span, + }) + } + } + Value::Filesize { val, span } => { + if val.is_negative() { + Err(ShellError::NeedsPositiveValue(*span)) + } else { + Ok(Spanned { + item: *val as usize, + span: *span, + }) + } + } + Value::Duration { val, span } => { + if val.is_negative() { + Err(ShellError::NeedsPositiveValue(*span)) + } else { + Ok(Spanned { + item: *val as usize, + span: *span, + }) + } + } v => Err(ShellError::CantConvert( - "integer".into(), + "non-negative integer".into(), v.get_type().to_string(), v.span()?, )), @@ -121,12 +139,30 @@ impl FromValue for Spanned { impl FromValue for usize { fn from_value(v: &Value) -> Result { match v { - Value::Int { val, .. } => Ok(*val as usize), - Value::Filesize { val, .. } => Ok(*val as usize), - Value::Duration { val, .. } => Ok(*val as usize), + Value::Int { val, span } => { + if val.is_negative() { + Err(ShellError::NeedsPositiveValue(*span)) + } else { + Ok(*val as usize) + } + } + Value::Filesize { val, span } => { + if val.is_negative() { + Err(ShellError::NeedsPositiveValue(*span)) + } else { + Ok(*val as usize) + } + } + Value::Duration { val, span } => { + if val.is_negative() { + Err(ShellError::NeedsPositiveValue(*span)) + } else { + Ok(*val as usize) + } + } v => Err(ShellError::CantConvert( - "integer".into(), + "non-negative integer".into(), v.get_type().to_string(), v.span()?, )), @@ -203,12 +239,18 @@ impl FromValue for CellPath { span, }], }), - Value::Int { val, .. } => Ok(CellPath { - members: vec![PathMember::Int { - val: *val as usize, - span, - }], - }), + Value::Int { val, span } => { + if val.is_negative() { + Err(ShellError::NeedsPositiveValue(*span)) + } else { + Ok(CellPath { + members: vec![PathMember::Int { + val: *val as usize, + span: *span, + }], + }) + } + } x => Err(ShellError::CantConvert( "cell path".into(), x.get_type().to_string(), diff --git a/docs/commands/git_checkout.md b/docs/commands/git_checkout.md deleted file mode 100644 index 25e5d9049b..0000000000 --- a/docs/commands/git_checkout.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: git checkout -layout: command -version: 0.59.0 ---- - - - -## Signature - -```> git checkout (branch)``` - -## Parameters - - - `branch`: - diff --git a/docs/commands/git_push.md b/docs/commands/git_push.md deleted file mode 100644 index 835829a249..0000000000 --- a/docs/commands/git_push.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: git push -layout: command -version: 0.59.0 ---- - - - -## Signature - -```> git push (remote) (branch)``` - -## Parameters - - - `remote`: - - `branch`: - diff --git a/docs/commands/post.md b/docs/commands/post.md index 66c7a63480..d369260dcf 100644 --- a/docs/commands/post.md +++ b/docs/commands/post.md @@ -8,7 +8,7 @@ Post a body to a URL (HTTP POST operation). ## Signature -```> post (path) (body) --user --password --content-type --content-length --raw --insecure``` +```> post (path) (body) --user --password --content-type --content-length --headers --raw --insecure``` ## Parameters @@ -18,6 +18,7 @@ Post a body to a URL (HTTP POST operation). - `--password {any}`: the password when authenticating - `--content-type {any}`: the MIME type of content to post - `--content-length {any}`: the length of the content being posted + - `--headers {any}`: custom headers you want to add - `--raw`: return values as a string instead of a table - `--insecure`: allow insecure server connections when using SSL @@ -33,3 +34,8 @@ Post content to url.com, with username and password > post -u myuser -p mypass url.com 'body' ``` +Post content to url.com, with custom header +```shell +> post -H [my-header-key my-header-value] url.com +``` + diff --git a/docs/make_docs.nu b/docs/make_docs.nu index 355013de3b..33a9479f33 100644 --- a/docs/make_docs.nu +++ b/docs/make_docs.nu @@ -1,6 +1,6 @@ let vers = (version).version -for command in ($scope.commands | where is_custom == $false) { +for command in ($scope.commands | where is_custom == $false && is_external == $false) { let top = $"--- title: ($command.command) layout: command @@ -61,5 +61,6 @@ $"($example.description) let safe_name = ($command.command | str find-replace '\?' '' | str find-replace ' ' '_') $doc | save --raw $"./docs/commands/($safe_name).md" + $"./docs/commands/($safe_name).md" } | length | $"($in) commands written" diff --git a/src/default_config.nu b/src/default_config.nu index b394d1c03d..70281f3f2d 100644 --- a/src/default_config.nu +++ b/src/default_config.nu @@ -132,8 +132,8 @@ let $config = { cellpath: white } use_grid_icons: $true - footer_mode: always # always, never, number_of_rows, auto - quick_completions: $false # set this to $true to auto-select completions when only one remains + footer_mode: "30" # always, never, number_of_rows, auto + quick_completions: $true # set this to $false to prevent auto-selecting completions when only one remains animate_prompt: $false # redraw the prompt every second float_precision: 2 use_ansi_coloring: $true