You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"can't convert list<string> to string" but I don't want to #7033
# Use `rhash` to get SHA-512 hash.
export def "hash sha512" [
--path (-p): bool
--size (-s): bool
--all (-a): bool
] {
let input =$inlet span = (metadata $input).span
if ($input| any ($it| path exists) == false) {
error make {
msg: "At least one of the files provided does not exist."
label: {
text: "Input contains file, that does not exist."
start: $span.start
end: $span.end
}
}
}
let options =if$all {
[[fmt columns]; ['%p,%f,%s B,%{Sha-512}' ["path" "name" "size" "hash"]]]
} elseif$path {
[[fmt columns]; ['%p,%{Sha-512}' ["path" "hash"]]]
} elseif$size {
[[fmt columns]; ['%f,%s B,%{Sha-512}' ["name" "size" "hash"]]]
} else {
[[fmt columns]; ['%f,%{Sha-512}' ["name" "hash"]]]
}
rhash $"--printf=($options | get fmt.0)"$input| split column ',' ($options| get columns.0 )
}
I don't want to convert ["name" "hash"] to a single string, but Nu seems to try to do it and fails at it.
Describe the solution you'd like
I want it to be two separate strings, so split column can accept them as its rest parameter.
Describe alternatives you've considered
Played around with all kinds of column, split and str commands, but none of them worked in this case.
Additional context and details
In Bash, that would be the following.
test-arg-count.sh
functionshow_args {
## Reliable way of showing the## number of arguments given.## Useful for debugging Bash behaviour.printf"%d args:""$#"printf" <%s>""$@"echo
}
show_args "$@"
Run
bash test-sep-cmd.sh my nu style is nyce
5 args: <my><nu><style><is><nyce>
We provide 5 separate strings, so this is what we get. However, Nu cannot seem to make that happen with the list provided in the example above.
Reacted by Jan Christoph Ebersbach and Grégoire Geis
Activity
rgwood commentedon Mar 1, 2023
Please provide a minimal reproduction.
theAkito commentedon Mar 3, 2023
Works
Does not work
Zoybean commentedon Feb 12, 2024
You should be able to use the spread operator (
...), replacing$owith...$o, like so:The spread operator unpacks a list into a sequence of parameters to a function, and appears to do what you wanted.
kubouch commentedon Apr 20, 2024
seems to work now.