nushell icon indicating copy to clipboard operation
nushell copied to clipboard

Did the commands in Nushell need to support `--` flag ?

Open yhm-amber opened this issue 3 years ago • 2 comments

Question

Did the commands in Nushell need to support -- flag ?

Additional context and details

For most of gnu/linux command, they have the -- flag, like this:

S21208-16031405

It divide the parameters and flags in args. Before it is flags and theirs value if have, after it is all paras.

this

cat -n foo path/to/bar baz

will be parsed as

cat -n -- foo path/to/bar baz

so they are same. And if you write cat -n -- foo path/to/bar baz in your code, things can be more clearly: the foo is not a value for -n flag.

Here, cat command is simple enough, so even users see code like cat -n foo , they can just run cat --help and spend time to read it and they will understand foo is not a value for -n but a param.

But, when some command have flag that can give zero or one value to it, if don't use -- , confuse will be easy.

So, I think make ls -a -- . and all the other commands in Nushell support -- flag/option, could be a good idea. 🙃

(Just if all the commands in Nushell both will be only one value in para, such as now I can't run ls foo bar in Nushell ... if this is the feature/style, then there is no need to let -- be a flag for all these commands in Nushell I think. 🙃)

yhm-amber avatar Dec 08 '22 08:12 yhm-amber

Current workaround is to use array unpack:

cat -n ...[foo path/to/bar baz]

weirdan avatar Aug 15 '24 18:08 weirdan

I mean -- will make the command much more clear, it divide args to options and params.

Such as, I can write

cat -n -- ...[foo path/to/bar baz]

and it is same as

cat -n ...[foo path/to/bar baz]

Without --, the command looks like ...[foo path/to/bar baz] maybe the value of option n; and with --, we can clear to see ...[foo path/to/bar baz] is just for param, not for value of any option.

I think, this ...[a b c] syntax is like {a,b,c} in shell, not corresponding to -- syntax which is a mark for divide two different part that easily to confused.

yhm-amber avatar Aug 18 '24 06:08 yhm-amber

Yeah. @Bahex is going to implement such feature in #16074. I'd like to close the issue because it's answered :-)

WindSoilder avatar Jul 17 '25 11:07 WindSoilder