davetron5000 / gli

Make awesome command-line applications the easy way
http://davetron5000.github.io/gli
Apache License 2.0
1.26k stars 102 forks source link

default_value output is incorrect when type is supplied #285

Open logicminds opened 5 years ago

logicminds commented 5 years ago

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"

davetron5000 commented 5 years ago

I see, yeah, agreed this should be better.

logicminds commented 3 years ago

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
davetron5000 commented 1 month ago

See #326 as it's related