gli icon indicating copy to clipboard operation
gli copied to clipboard

default_value output is incorrect when type is supplied

Open logicminds opened this issue 5 years ago • 2 comments

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"

logicminds avatar Dec 18 '18 19:12 logicminds

I see, yeah, agreed this should be better.

davetron5000 avatar Jan 01 '19 21:01 davetron5000

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

logicminds avatar Nov 08 '20 20:11 logicminds