jwaldrip / admiral.cr

A robust DSL for writing command line interfaces written in Crystal.
https://jwaldrip.github.com/admiral.cr
MIT License
135 stars 14 forks source link

Flag arrays with required false are still required #23

Closed gerrywastaken closed 4 years ago

gerrywastaken commented 4 years ago
require "admiral"

class Main < Admiral::Command
  define_flag bloop : Array(String),
    default: [] of String,
    required: false

  def run
    puts flags.bloop
  end
end

Main.run
> bin/cli_test 
Flag required: --bloop

Am I doing something wrong?

Actually this seems a bit odd. The default must be nil or not a boolean? https://github.com/jwaldrip/admiral.cr/blob/master/src/admiral/command/flag.cr#L288

edit: There also seems to be a related issue here where the type specification is change to type | nil unless the type is set to required: https://github.com/jwaldrip/admiral.cr/blob/master/src/admiral/command/flag.cr#L321

So even when the first issue is fixed, the type of bloop is Array(String) | Nil instead of the requested Array(String)