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

Help does not work when required arguments are missing #12

Closed djmaze closed 6 years ago

djmaze commented 6 years ago

When a command has required arguments and help defined, it is not possible to get help without also specifying the required arguments at the command line. This is not an expected behaviour in my opinion.

# test.cr
require "admiral"

class TestCommand < Admiral::Command
  define_help description: "does foobar"
  define_argument foo : String, required: true
  define_argument bar : String, required: true

  def run
  end
end

TestCommand.run
$ ./crystal build test.cr
$ ./test --help
Missing required attribute: <foo>
$ ./test one --help  
Missing required attribute: <bar>
$ ./test one two --help
Usage:
  ./test [flags...] <foo> <bar> [arg...]

does foobar

Flags:
  --help          # Displays help for the current command.

Arguments:
  foo (required)
  bar (required)
djmaze commented 6 years ago

It looks just moving puts_help and puts_version to the top of this list does the trick.