Shopify/cli-kit

Questions about `option` and `option!`

bmassemin opened this issue · 1 comments

I'm trying to code a new command line using cli-kit, and I was wondering if I'm correctly understandingoption and option!.
My understanding is option is an optional parameter, while option! is a required parameter.
But looking at the code they are both not required (here and here).

Also, if I try to set a non Nil default with option, I have the following error message:

ArgumentError: declare options with non-nil defaults using `option!` instead of `option`

I guess it should be option instead of option!.

Let me know if I misunderstood how it works, and also how I can use something same as option with required

option! will always return a string, giving the default value if one is not specified at the command line. option will sometimes give a string, and sometimes a nil. You can see this in the Sorbet signatures:

).returns(T.nilable(String))
end
def option(name: infer_name, short: nil, long: nil, desc: nil, default: nil)

vs

).returns(String)
end
def option!(name: infer_name, short: nil, long: nil, desc: nil, default: nil)

You are correct that neither is required. If you need something to be required, you'll need a required positional argument. We see options as inherently optional.