Skip to content

Commit

Permalink
Use int type name consistently (nushell#10579)
Browse files Browse the repository at this point in the history
# Description
When referring to the type use `int` consistently. Only when referring
to the concept of integer numbers use `integer`.

- Fix `random integer` to `random int` tests
  - Forgot in nushell#10520
- Use int instead of integer in error messages
- Use int type name in bits commands
- Fix messages in `for` examples
- Use int typename in `into` commands
- Use int typename in rest of commands
- Report errors in `nu-protocol` with int typename

Work for nushell#10332 

# User-Facing Changes
User errorrs should now use `int` so you can easily find the necessary
commands or type annotations.

# Tests + Formatting
Only two tests found that needed updating
  • Loading branch information
sholderbach authored and hardfau1t committed Dec 14, 2023
1 parent cb28f86 commit 7b1a20e
Show file tree
Hide file tree
Showing 36 changed files with 77 additions and 93 deletions.
2 changes: 1 addition & 1 deletion crates/nu-cli/src/commands/commandline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Command for Commandline {
from_type: "string".to_string(),
span: cmd.span(),
help: Some(format!(
r#"string "{cmd_str}" does not represent a valid integer"#
r#"string "{cmd_str}" does not represent a valid int"#
)),
})
}
Expand Down
10 changes: 3 additions & 7 deletions crates/nu-cmd-extra/src/extra/bits/and.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ impl Command for BitsAnd {
Type::List(Box::new(Type::Int)),
),
])
.required(
"target",
SyntaxShape::Int,
"target integer to perform bit and",
)
.required("target", SyntaxShape::Int, "target int to perform bit and")
.category(Category::Bits)
}

fn usage(&self) -> &str {
"Performs bitwise and for integers."
"Performs bitwise and for ints."
}

fn search_terms(&self) -> Vec<&str> {
Expand Down Expand Up @@ -85,7 +81,7 @@ fn operate(value: Value, target: i64, head: Span) -> Value {
Value::Error { .. } => value,
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "integer".into(),
exp_input_type: "int".into(),
wrong_type: other.get_type().to_string(),
dst_span: head,
src_span: other.span(),
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-cmd-extra/src/extra/bits/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pub fn action(input: &Value, _args: &Arguments, span: Span) -> Value {
Value::Error { .. } => input.clone(),
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "integer, filesize, string, date, duration, binary or bool".into(),
exp_input_type: "int, filesize, string, date, duration, binary, or bool".into(),
wrong_type: other.get_type().to_string(),
dst_span: span,
src_span: other.span(),
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-cmd-extra/src/extra/bits/not.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn operate(value: Value, head: Span, signed: bool, number_size: NumberBytes) ->
Value::Error { .. } => other,
_ => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "integer".into(),
exp_input_type: "int".into(),
wrong_type: other.get_type().to_string(),
dst_span: head,
src_span: other.span(),
Expand Down
10 changes: 3 additions & 7 deletions crates/nu-cmd-extra/src/extra/bits/or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ impl Command for BitsOr {
Type::List(Box::new(Type::Int)),
),
])
.required(
"target",
SyntaxShape::Int,
"target integer to perform bit or",
)
.required("target", SyntaxShape::Int, "target int to perform bit or")
.category(Category::Bits)
}

fn usage(&self) -> &str {
"Performs bitwise or for integers."
"Performs bitwise or for ints."
}

fn search_terms(&self) -> Vec<&str> {
Expand Down Expand Up @@ -85,7 +81,7 @@ fn operate(value: Value, target: i64, head: Span) -> Value {
Value::Error { .. } => value,
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "integer".into(),
exp_input_type: "int".into(),
wrong_type: other.get_type().to_string(),
dst_span: head,
src_span: other.span(),
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-cmd-extra/src/extra/bits/rotate_left.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Command for BitsRol {
}

fn usage(&self) -> &str {
"Bitwise rotate left for integers."
"Bitwise rotate left for ints."
}

fn search_terms(&self) -> Vec<&str> {
Expand Down Expand Up @@ -145,7 +145,7 @@ fn operate(value: Value, bits: usize, head: Span, signed: bool, number_size: Num
Value::Error { .. } => value,
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "integer".into(),
exp_input_type: "int".into(),
wrong_type: other.get_type().to_string(),
dst_span: head,
src_span: other.span(),
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-cmd-extra/src/extra/bits/rotate_right.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Command for BitsRor {
}

fn usage(&self) -> &str {
"Bitwise rotate right for integers."
"Bitwise rotate right for ints."
}

fn search_terms(&self) -> Vec<&str> {
Expand Down Expand Up @@ -149,7 +149,7 @@ fn operate(value: Value, bits: usize, head: Span, signed: bool, number_size: Num
Value::Error { .. } => value,
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "integer".into(),
exp_input_type: "int".into(),
wrong_type: other.get_type().to_string(),
dst_span: head,
src_span: other.span(),
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-cmd-extra/src/extra/bits/shift_left.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Command for BitsShl {
}

fn usage(&self) -> &str {
"Bitwise shift left for integers."
"Bitwise shift left for ints."
}

fn search_terms(&self) -> Vec<&str> {
Expand Down Expand Up @@ -169,7 +169,7 @@ fn operate(value: Value, bits: usize, head: Span, signed: bool, number_size: Num
Value::Error { .. } => value,
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "integer".into(),
exp_input_type: "int".into(),
wrong_type: other.get_type().to_string(),
dst_span: head,
src_span: other.span(),
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-cmd-extra/src/extra/bits/shift_right.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Command for BitsShr {
}

fn usage(&self) -> &str {
"Bitwise shift right for integers."
"Bitwise shift right for ints."
}

fn search_terms(&self) -> Vec<&str> {
Expand Down Expand Up @@ -159,7 +159,7 @@ fn operate(value: Value, bits: usize, head: Span, signed: bool, number_size: Num
Value::Error { .. } => value,
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "integer".into(),
exp_input_type: "int".into(),
wrong_type: other.get_type().to_string(),
dst_span: head,
src_span: other.span(),
Expand Down
10 changes: 3 additions & 7 deletions crates/nu-cmd-extra/src/extra/bits/xor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ impl Command for BitsXor {
Type::List(Box::new(Type::Int)),
),
])
.required(
"target",
SyntaxShape::Int,
"target integer to perform bit xor",
)
.required("target", SyntaxShape::Int, "target int to perform bit xor")
.category(Category::Bits)
}

fn usage(&self) -> &str {
"Performs bitwise xor for integers."
"Performs bitwise xor for ints."
}

fn search_terms(&self) -> Vec<&str> {
Expand Down Expand Up @@ -84,7 +80,7 @@ fn operate(value: Value, target: i64, head: Span) -> Value {
Value::Error { .. } => value,
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "integer".into(),
exp_input_type: "int".into(),
wrong_type: other.get_type().to_string(),
dst_span: head,
src_span: other.span(),
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-cmd-extra/src/extra/conversions/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
Value::Error { .. } => input.clone(),
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "float , integer or filesize".into(),
exp_input_type: "float, int, or filesize".into(),
wrong_type: other.get_type().to_string(),
dst_span: span,
src_span: other.span(),
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-cmd-lang/src/core_commands/for_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl Command for For {
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Echo the square of each integer",
description: "Print the square of each integer",
example: "for x in [1 2 3] { print ($x * $x) }",
result: None,
},
Expand All @@ -209,7 +209,7 @@ impl Command for For {
result: None,
},
Example {
description: "Number each item and echo a message",
description: "Number each item and print a message",
example:
"for $it in ['bob' 'fred'] --numbered { print $\"($it.index) is ($it.item)\" }",
result: None,
Expand Down
5 changes: 2 additions & 3 deletions crates/nu-command/src/conversions/into/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ impl Command for SubCommand {
)),
},
Example {
description:
"convert an integer to a nushell binary primitive with compact enabled",
description: "convert an int to a nushell binary primitive with compact enabled",
example: "10 | into binary --compact",
result: Some(Value::binary(vec![10], Span::test_data())),
},
Expand Down Expand Up @@ -172,7 +171,7 @@ pub fn action(input: &Value, _args: &Arguments, span: Span) -> Value {
Value::Error { .. } => input.clone(),
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "integer, float, filesize, string, date, duration, binary or bool"
exp_input_type: "int, float, filesize, string, date, duration, binary, or bool"
.into(),
wrong_type: other.get_type().to_string(),
dst_span: span,
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-command/src/conversions/into/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Command for SubCommand {
result: Some(Value::bool(true, span)),
},
Example {
description: "convert integer to boolean",
description: "convert int to boolean",
example: "1 | into bool",
result: Some(Value::bool(true, span)),
},
Expand Down Expand Up @@ -159,7 +159,7 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
Value::Error { .. } => input.clone(),
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "bool, integer, float or string".into(),
exp_input_type: "bool, int, float or string".into(),
wrong_type: other.get_type().to_string(),
dst_span: span,
src_span: other.span(),
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/conversions/into/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
other => {
return Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "string and integer".into(),
exp_input_type: "string and int".into(),
wrong_type: other.get_type().to_string(),
dst_span: head,
src_span: other.span(),
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/conversions/into/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, head: Span) -> Value {
Value::Error { .. } => input.clone(),
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "string, integer or bool".into(),
exp_input_type: "string, int, or bool".into(),
wrong_type: other.get_type().to_string(),
dst_span: head,
src_span: other.span(),
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/conversions/into/filesize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
Value::Nothing { .. } => Value::filesize(0, value_span),
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "string and integer".into(),
exp_input_type: "string and int".into(),
wrong_type: other.get_type().to_string(),
dst_span: span,
src_span: value_span,
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/conversions/into/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, head: Span) -> Value {
Value::Error { .. } => input.clone(),
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "string, integer or bool".into(),
exp_input_type: "string, int or bool".into(),
wrong_type: other.get_type().to_string(),
dst_span: head,
src_span: other.span(),
Expand Down
30 changes: 15 additions & 15 deletions crates/nu-command/src/conversions/into/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,65 +158,65 @@ impl Command for SubCommand {
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Convert string to integer in table",
description: "Convert string to int in table",
example: "[[num]; ['-5'] [4] [1.5]] | into int num",
result: None,
},
Example {
description: "Convert string to integer",
description: "Convert string to int",
example: "'2' | into int",
result: Some(Value::test_int(2)),
},
Example {
description: "Convert float to integer",
description: "Convert float to int",
example: "5.9 | into int",
result: Some(Value::test_int(5)),
},
Example {
description: "Convert decimal string to integer",
description: "Convert decimal string to int",
example: "'5.9' | into int",
result: Some(Value::test_int(5)),
},
Example {
description: "Convert file size to integer",
description: "Convert file size to int",
example: "4KB | into int",
result: Some(Value::test_int(4000)),
},
Example {
description: "Convert bool to integer",
description: "Convert bool to int",
example: "[false, true] | into int",
result: Some(Value::list(
vec![Value::test_int(0), Value::test_int(1)],
Span::test_data(),
)),
},
Example {
description: "Convert date to integer (Unix nanosecond timestamp)",
description: "Convert date to int (Unix nanosecond timestamp)",
example: "1983-04-13T12:09:14.123456789-05:00 | into int",
result: Some(Value::test_int(419101754123456789)),
},
Example {
description: "Convert to integer from binary",
description: "Convert to int from binary data (radix: 2)",
example: "'1101' | into int -r 2",
result: Some(Value::test_int(13)),
},
Example {
description: "Convert to integer from hex",
description: "Convert to int from hex",
example: "'FF' | into int -r 16",
result: Some(Value::test_int(255)),
},
Example {
description: "Convert octal string to integer",
description: "Convert octal string to int",
example: "'0o10132' | into int",
result: Some(Value::test_int(4186)),
},
Example {
description: "Convert 0 padded string to integer",
description: "Convert 0 padded string to int",
example: "'0010132' | into int",
result: Some(Value::test_int(10132)),
},
Example {
description: "Convert 0 padded string to integer with radix",
description: "Convert 0 padded string to int with radix 8",
example: "'0010132' | into int -r 8",
result: Some(Value::test_int(4186)),
},
Expand Down Expand Up @@ -248,7 +248,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
return Value::error(
ShellError::CantConvert {
to_type: "float".to_string(),
from_type: "integer".to_string(),
from_type: "int".to_string(),
span,
help: None,
},
Expand Down Expand Up @@ -327,7 +327,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
Value::Error { .. } => input.clone(),
other => Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "integer, float, filesize, date, string, binary, duration or bool"
exp_input_type: "int, float, filesize, date, string, binary, duration, or bool"
.into(),
wrong_type: other.get_type().to_string(),
dst_span: span,
Expand Down Expand Up @@ -376,7 +376,7 @@ fn convert_int(input: &Value, head: Span, radix: u32) -> Value {
other => {
return Value::error(
ShellError::OnlySupportsThisInputType {
exp_input_type: "string and integer".into(),
exp_input_type: "string and int".into(),
wrong_type: other.get_type().to_string(),
dst_span: head,
src_span: other.span(),
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/conversions/into/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Command for SubCommand {
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "convert integer to string and append three decimal places",
description: "convert int to string and append three decimal places",
example: "5 | into string -d 3",
result: Some(Value::test_string("5.000")),
},
Expand Down

0 comments on commit 7b1a20e

Please sign in to comment.