add a more verbose description of operators (#7263)

# Description

I was thinking that it may be helpful to have a more verbose description
of our operators. Please let me know if you have better wording.

Also, while not strictly considered an operator, i added `not` to avoid
some confusion.
<img width="1574" alt="Screenshot 2022-11-28 at 7 57 30 PM"
src="https://user-images.githubusercontent.com/343840/204419666-7c4dbb43-26f5-4cd5-9a4e-a1555a9e700f.png">


# User-Facing Changes

Adds description column

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
Darren Schroeder 2022-11-28 20:20:17 -06:00 committed by GitHub
parent 7d5333db3b
commit 5d2abdd1c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,6 +40,8 @@ impl Command for HelpOperators {
vals.push(Value::string(op.operator, head)); vals.push(Value::string(op.operator, head));
cols.push("name".into()); cols.push("name".into());
vals.push(Value::string(op.name, head)); vals.push(Value::string(op.name, head));
cols.push("description".into());
vals.push(Value::string(op.description, head));
cols.push("precedence".into()); cols.push("precedence".into());
vals.push(Value::int(op.precedence, head)); vals.push(Value::int(op.precedence, head));
recs.push(Value::Record { recs.push(Value::Record {
@ -59,6 +61,7 @@ struct OperatorInfo {
op_type: String, op_type: String,
operator: String, operator: String,
name: String, name: String,
description: String,
precedence: i64, precedence: i64,
} }
@ -68,210 +71,252 @@ fn generate_operator_info() -> Vec<OperatorInfo> {
op_type: "Assignment".into(), op_type: "Assignment".into(),
operator: "=".into(), operator: "=".into(),
name: "Assign".into(), name: "Assign".into(),
description: "Assigns a value to a variable.".into(),
precedence: 10, precedence: 10,
}, },
OperatorInfo { OperatorInfo {
op_type: "Assignment".into(), op_type: "Assignment".into(),
operator: "+=".into(), operator: "+=".into(),
name: "PlusAssign".into(), name: "PlusAssign".into(),
description: "Adds a value to a variable.".into(),
precedence: 10, precedence: 10,
}, },
OperatorInfo { OperatorInfo {
op_type: "Assignment".into(), op_type: "Assignment".into(),
operator: "-=".into(), operator: "-=".into(),
name: "MinusAssign".into(), name: "MinusAssign".into(),
description: "Subtracts a value from a variable.".into(),
precedence: 10, precedence: 10,
}, },
OperatorInfo { OperatorInfo {
op_type: "Assignment".into(), op_type: "Assignment".into(),
operator: "*=".into(), operator: "*=".into(),
name: "MultiplyAssign".into(), name: "MultiplyAssign".into(),
description: "Multiplies a variable by a value.".into(),
precedence: 10, precedence: 10,
}, },
OperatorInfo { OperatorInfo {
op_type: "Assignment".into(), op_type: "Assignment".into(),
operator: "/=".into(), operator: "/=".into(),
name: "DivideAssign".into(), name: "DivideAssign".into(),
description: "Divides a variable by a value.".into(),
precedence: 10, precedence: 10,
}, },
OperatorInfo { OperatorInfo {
op_type: "Comparison".into(), op_type: "Comparison".into(),
operator: "==".into(), operator: "==".into(),
name: "Equal".into(), name: "Equal".into(),
description: "Checks if two values are equal.".into(),
precedence: 80, precedence: 80,
}, },
OperatorInfo { OperatorInfo {
op_type: "Comparison".into(), op_type: "Comparison".into(),
operator: "!=".into(), operator: "!=".into(),
name: "NotEqual".into(), name: "NotEqual".into(),
description: "Checks if two values are not equal.".into(),
precedence: 80, precedence: 80,
}, },
OperatorInfo { OperatorInfo {
op_type: "Comparison".into(), op_type: "Comparison".into(),
operator: "<".into(), operator: "<".into(),
name: "LessThan".into(), name: "LessThan".into(),
description: "Checks if a value is less than another.".into(),
precedence: 80, precedence: 80,
}, },
OperatorInfo { OperatorInfo {
op_type: "Comparison".into(), op_type: "Comparison".into(),
operator: "<=".into(), operator: "<=".into(),
name: "LessThanOrEqual".into(), name: "LessThanOrEqual".into(),
description: "Checks if a value is less than or equal to another.".into(),
precedence: 80, precedence: 80,
}, },
OperatorInfo { OperatorInfo {
op_type: "Comparison".into(), op_type: "Comparison".into(),
operator: ">".into(), operator: ">".into(),
name: "GreaterThan".into(), name: "GreaterThan".into(),
description: "Checks if a value is greater than another.".into(),
precedence: 80, precedence: 80,
}, },
OperatorInfo { OperatorInfo {
op_type: "Comparison".into(), op_type: "Comparison".into(),
operator: ">=".into(), operator: ">=".into(),
name: "GreaterThanOrEqual".into(), name: "GreaterThanOrEqual".into(),
description: "Checks if a value is greater than or equal to another.".into(),
precedence: 80, precedence: 80,
}, },
OperatorInfo { OperatorInfo {
op_type: "Comparison".into(), op_type: "Comparison".into(),
operator: "=~".into(), operator: "=~".into(),
name: "RegexMatch".into(), name: "RegexMatch".into(),
description: "Checks if a value matches a regular expression.".into(),
precedence: 80, precedence: 80,
}, },
OperatorInfo { OperatorInfo {
op_type: "Comparison".into(), op_type: "Comparison".into(),
operator: "!~".into(), operator: "!~".into(),
name: "NotRegexMatch".into(), name: "NotRegexMatch".into(),
description: "Checks if a value does not match a regular expression.".into(),
precedence: 80, precedence: 80,
}, },
OperatorInfo { OperatorInfo {
op_type: "Comparison".into(), op_type: "Comparison".into(),
operator: "in".into(), operator: "in".into(),
name: "In".into(), name: "In".into(),
description: "Checks if a value is in a list or string.".into(),
precedence: 80, precedence: 80,
}, },
OperatorInfo { OperatorInfo {
op_type: "Comparison".into(), op_type: "Comparison".into(),
operator: "not-in".into(), operator: "not-in".into(),
name: "NotIn".into(), name: "NotIn".into(),
description: "Checks if a value is not in a list or string.".into(),
precedence: 80, precedence: 80,
}, },
OperatorInfo { OperatorInfo {
op_type: "Comparison".into(), op_type: "Comparison".into(),
operator: "starts-with".into(), operator: "starts-with".into(),
name: "StartsWith".into(), name: "StartsWith".into(),
description: "Checks if a string starts with another.".into(),
precedence: 80, precedence: 80,
}, },
OperatorInfo { OperatorInfo {
op_type: "Comparison".into(), op_type: "Comparison".into(),
operator: "ends-with".into(), operator: "ends-with".into(),
name: "EndsWith".into(), name: "EndsWith".into(),
description: "Checks if a string ends with another.".into(),
precedence: 80, precedence: 80,
}, },
OperatorInfo {
op_type: "Comparison".into(),
operator: "not".into(),
name: "UnaryNot".into(),
description: "Negates a value or expression.".into(),
precedence: 0,
},
OperatorInfo { OperatorInfo {
op_type: "Math".into(), op_type: "Math".into(),
operator: "+".into(), operator: "+".into(),
name: "Plus".into(), name: "Plus".into(),
description: "Adds two values.".into(),
precedence: 90, precedence: 90,
}, },
OperatorInfo { OperatorInfo {
op_type: "Math".into(), op_type: "Math".into(),
operator: "++".into(), operator: "++".into(),
name: "Append".into(), name: "Append".into(),
description: "Appends two lists or a list and a value.".into(),
precedence: 80, precedence: 80,
}, },
OperatorInfo { OperatorInfo {
op_type: "Math".into(), op_type: "Math".into(),
operator: "-".into(), operator: "-".into(),
name: "Minus".into(), name: "Minus".into(),
description: "Subtracts two values.".into(),
precedence: 90, precedence: 90,
}, },
OperatorInfo { OperatorInfo {
op_type: "Math".into(), op_type: "Math".into(),
operator: "*".into(), operator: "*".into(),
name: "Multiply".into(), name: "Multiply".into(),
description: "Multiplies two values.".into(),
precedence: 95, precedence: 95,
}, },
OperatorInfo { OperatorInfo {
op_type: "Math".into(), op_type: "Math".into(),
operator: "/".into(), operator: "/".into(),
name: "Divide".into(), name: "Divide".into(),
description: "Divides two values.".into(),
precedence: 95, precedence: 95,
}, },
OperatorInfo { OperatorInfo {
op_type: "Math".into(), op_type: "Math".into(),
operator: "//".into(), operator: "//".into(),
name: "FloorDivision".into(), name: "FloorDivision".into(),
description: "Divides two values and floors the result.".into(),
precedence: 95, precedence: 95,
}, },
OperatorInfo { OperatorInfo {
op_type: "Math".into(), op_type: "Math".into(),
operator: "mod".into(), operator: "mod".into(),
name: "Modulo".into(), name: "Modulo".into(),
description: "Divides two values and returns the remainder.".into(),
precedence: 95, precedence: 95,
}, },
OperatorInfo { OperatorInfo {
op_type: "Math".into(), op_type: "Math".into(),
operator: "**".into(), operator: "**".into(),
name: "Pow ".into(), name: "Pow ".into(),
description: "Raises one value to the power of another.".into(),
precedence: 100, precedence: 100,
}, },
OperatorInfo { OperatorInfo {
op_type: "Bitwise".into(), op_type: "Bitwise".into(),
operator: "bit-or".into(), operator: "bit-or".into(),
name: "BitOr".into(), name: "BitOr".into(),
description: "Performs a bitwise OR on two values.".into(),
precedence: 60, precedence: 60,
}, },
OperatorInfo { OperatorInfo {
op_type: "Bitwise".into(), op_type: "Bitwise".into(),
operator: "bit-xor".into(), operator: "bit-xor".into(),
name: "BitXor".into(), name: "BitXor".into(),
description: "Performs a bitwise XOR on two values.".into(),
precedence: 70, precedence: 70,
}, },
OperatorInfo { OperatorInfo {
op_type: "Bitwise".into(), op_type: "Bitwise".into(),
operator: "bit-and".into(), operator: "bit-and".into(),
name: "BitAnd".into(), name: "BitAnd".into(),
description: "Performs a bitwise AND on two values.".into(),
precedence: 75, precedence: 75,
}, },
OperatorInfo { OperatorInfo {
op_type: "Bitwise".into(), op_type: "Bitwise".into(),
operator: "bit-shl".into(), operator: "bit-shl".into(),
name: "ShiftLeft".into(), name: "ShiftLeft".into(),
description: "Shifts a value left by another.".into(),
precedence: 85, precedence: 85,
}, },
OperatorInfo { OperatorInfo {
op_type: "Bitwise".into(), op_type: "Bitwise".into(),
operator: "bit-shr".into(), operator: "bit-shr".into(),
name: "ShiftRight".into(), name: "ShiftRight".into(),
description: "Shifts a value right by another.".into(),
precedence: 85, precedence: 85,
}, },
OperatorInfo { OperatorInfo {
op_type: "Boolean".into(), op_type: "Boolean".into(),
operator: "&&".into(), operator: "&&".into(),
name: "And".into(), name: "And".into(),
description: "Deprecated. Checks if two values are true.".into(),
precedence: 50, precedence: 50,
}, },
OperatorInfo { OperatorInfo {
op_type: "Boolean".into(), op_type: "Boolean".into(),
operator: "and".into(), operator: "and".into(),
name: "And".into(), name: "And".into(),
description: "Checks if two values are true.".into(),
precedence: 50, precedence: 50,
}, },
OperatorInfo { OperatorInfo {
op_type: "Boolean".into(), op_type: "Boolean".into(),
operator: "||".into(), operator: "||".into(),
name: "Or".into(), name: "Or".into(),
description: "Deprecated. Checks if either value is true.".into(),
precedence: 40, precedence: 40,
}, },
OperatorInfo { OperatorInfo {
op_type: "Boolean".into(), op_type: "Boolean".into(),
operator: "or".into(), operator: "or".into(),
name: "Or".into(), name: "Or".into(),
description: "Checks if either value is true.".into(),
precedence: 40, precedence: 40,
}, },
OperatorInfo { OperatorInfo {
op_type: "Boolean".into(), op_type: "Boolean".into(),
operator: "xor".into(), operator: "xor".into(),
name: "Xor".into(), name: "Xor".into(),
description: "Checks if one value is true and the other is false.".into(),
precedence: 45, precedence: 45,
}, },
] ]