gli
gli copied to clipboard
default_value output is incorrect when type is supplied
Example:
$ cb help
GLOBAL OPTIONS
--exporters=arg - List of exporters to transform the data (default: ["table", "stdout"])
--help - Show this message
--version - Display the program version
The default in the flag help output contains an array:
default: ["table", "stdout"]
However, when a user supplies this value they might think they need to supply ["table", "stdout"]
Flag attribute is configured like so:
flag [:exporters], desc: "List of exporters to transform the data", default_value: ['table','stdout'], type: Array
However, when a user is supplying the flag they would use --exporters=table,stdout
and not --exporters=['table','stdout']
This is confusing for the user. The default_value value should be a real world value that will be processed by the type conversion system of GLI.
default_value: "table,stdout"
I see, yeah, agreed this should be better.
As a workaround I just changed the type to String and processed the incoming value.
flag [:exporters], desc: "List of exporters to transform the data", default_value: 'table,stdout', type: String
I don't know if transforming the data in the pre is abusing this pre block, but I didn't see another way. A transform block on the flag would have been nice to pass in.
pre do |_global, command, options, _args|
options[:exporters] = options[:exporters].split(',')
end