-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Option.parseArgs
with variadic and default options
#1641
Comments
Nice example and description, thanks. You have hit a tricky part of the option-argument processing! Long story... The "default value" for an option is used in two ways: it is set as the option value when the option is added to the command, and also the default value gets passed into the argument parser as the "previous" value the first time the parser is called. This often works fine. With a variadic option you probably want the command-line items in a fresh array without the default value, and Commander does some extra work to make this happen when you don't have a custom parser. The internal support for adding to variadic options makes a fresh array if the previous value is the default value. Line 105 in 43f4743
Four different work-around ideas for your use case:
Ask if you would like to see code for one of those approaches. (I have wondered about adding the ability to set the Option default value and the starting value separately. And wondered about passing in Option object and even Command into parse function. But not many reports of problems to justify the additional complexity so far, so only been thinking about it!) |
FYI: a custom |
Thanks a lot for all this information - those work-arounds will work just fine for me. Appreciate the help. |
I'm trying to create an
Option
that supports:parseArgs
function)However, I'm noticing that there's some interference between my
parseArgs
function and specification of a default value. Consider the following minimal example, where I hypothetically want to provide multiple ports in the arguments, but want to default to a single port 80 if none are provided:Executing this with
--port 123 124
provides the following output:Without the
argParser
added, I get the expected{ port: [ '123', '124' ] }
, but I'm no longer able to validate the provided arguments. It seems thatargParser
is also parsing the default port as well, and appending this to the returned list. Is there a way to circumvent this?The text was updated successfully, but these errors were encountered: