mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
change str distance to output value::int (#6963)
* change str distance to output value::int * update the test
This commit is contained in:
parent
0b4daa66b0
commit
f48de73236
2 changed files with 8 additions and 12 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -22,6 +22,10 @@ debian/nu/
|
||||||
# VSCode's IDE items
|
# VSCode's IDE items
|
||||||
.vscode/*
|
.vscode/*
|
||||||
|
|
||||||
|
# Visual Studio Extension SourceGear Rust items
|
||||||
|
VSWorkspaceSettings.json
|
||||||
|
unstable_cargo_features.txt
|
||||||
|
|
||||||
# Helix configuration folder
|
# Helix configuration folder
|
||||||
.helix/*
|
.helix/*
|
||||||
.helix
|
.helix
|
||||||
|
|
|
@ -70,12 +70,8 @@ impl Command for SubCommand {
|
||||||
vec![Example {
|
vec![Example {
|
||||||
description: "get the edit distance between two strings",
|
description: "get the edit distance between two strings",
|
||||||
example: "'nushell' | str distance 'nutshell'",
|
example: "'nushell' | str distance 'nutshell'",
|
||||||
result: Some(Value::Record {
|
result: Some(Value::Int {
|
||||||
cols: vec!["distance".to_string()],
|
val: 1,
|
||||||
vals: vec![Value::Int {
|
|
||||||
val: 1,
|
|
||||||
span: Span::test_data(),
|
|
||||||
}],
|
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
}]
|
}]
|
||||||
|
@ -87,12 +83,8 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||||
match &input {
|
match &input {
|
||||||
Value::String { val, .. } => {
|
Value::String { val, .. } => {
|
||||||
let distance = levenshtein_distance(val, compare_string);
|
let distance = levenshtein_distance(val, compare_string);
|
||||||
Value::Record {
|
Value::Int {
|
||||||
cols: vec!["distance".to_string()],
|
val: distance as i64,
|
||||||
vals: vec![Value::Int {
|
|
||||||
val: distance as i64,
|
|
||||||
span: head,
|
|
||||||
}],
|
|
||||||
span: head,
|
span: head,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue