A few fixes to docs generation and default config (#4570)

* A few fixes to docs generation and default config

* A few more fixes
This commit is contained in:
JT
2022-02-20 15:20:41 -05:00
committed by GitHub
parent 6024a17a5b
commit 2ba12afb01
9 changed files with 88 additions and 62 deletions

View File

@ -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(),

View File

@ -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),

View File

@ -96,21 +96,39 @@ impl FromValue for f64 {
impl FromValue for Spanned<usize> {
fn from_value(v: &Value) -> Result<Self, ShellError> {
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<usize> {
impl FromValue for usize {
fn from_value(v: &Value) -> Result<Self, ShellError> {
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(),