`-` value seem not to work when passed to `Option.String` as option
Closed this issue · 3 comments
Hello and first thank you for the good work on this library.
I wanted to report an issue that I found while working a small utility :
I wanted to add an option to my tool which can optionally take -
as value (a pattern commonly seen on cli tools for redirecting some output on stdout instead of a file)
class BuildContextCommand extends clipanion.Command {
public static paths = [ [ 'docker', 'build-context' ] ]
public static usage = {
description: 'builds an efficient docker context .tgz from a yarn workspace'
}
public output = clipanion.Option.String(`-o,--output`, {
description: `the tgz output, use '-' to write contents to stdout (useful for piping to docker)`,
required: false
})
public execute = async () => { console.log(this.output) }
}
clipanion seem to fail not recognizing this value:
hb docker build-context -o -
Unknown Syntax Error: Not enough arguments to option -o.
$ hb docker build-context [-o,--output #0] [input]
It's working when using the =
form though:
hb docker build-context -o=-
-
maybe it's interpreted as another (positional/option) argument ?
macos 11.3
node v14.15.4
clipanion: 3.0.0-rc.12
Thank you,
I'm hitting this as well. I assume the fix is to treat any argv entry that is -
as being a string, not a flag.
The only ambiguity would be if you wanted to declare an optional flag that was named '' (empty string) like this:
thisOptionHasEmptyName: Option.String('-')
I'm not sure if that works and I'm pretty sure it should not be supported, but maybe there are CLIs that need this feature?
Yep, I think it'd be fine to special-case -
out of the options ("empty option" is already prevented by the regexp). It should only be a matter of replacing the startsWith
calls with an helper that checks for "t"
.
Should be fixed in 3.0.0
.