Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required options raise exception if not provided #48

Closed
DannyBen opened this issue Nov 12, 2019 · 2 comments · Fixed by #66
Closed

Required options raise exception if not provided #48

DannyBen opened this issue Nov 12, 2019 · 2 comments · Fixed by #66

Comments

@DannyBen
Copy link

DannyBen commented Nov 12, 2019

Hello,

I am not sure if this is a design choice or not.
It seems like in some cases, Clim handles exceptions on its own, and shows a friendly error to the user, and in other cases, it does not.

  • "Option that requires an argument" - this prints a friendly error
  • "Required options" - this raises an exception

Sample code

# src/bug1.cr
require "clim"

module Hello
  class Cli < Clim
    main do
      usage "hello <name>"
      option "--prefix <text>", type: String, desc: "Prefix.", required: true
      
      run do |opts, args|
        puts "ok"
      end
    end
  end
end

Hello::Cli.start(ARGV)

Actual behavior

$ crystal run src/bug1.cr -- --prefix
ERROR: Option that requires an argument. "--prefix"

Please see the `--help`.


$ crystal run src/bug1.cr -- --prefix a
ok


$ crystal run src/bug1.cr
Unhandled exception: Required options. "--prefix <text>" (Exception)
  from lib/clim/src/clim/command/parser.cr:31:11 in 'required_validate!'
  from lib/clim/src/clim/command.cr:79:7 in 'parse_by_parser'
  from lib/clim/src/clim/command.cr:72:14 in 'recursive_parse'
  from lib/clim/src/clim/command.cr:62:7 in 'parse'
  ... snip ...

Expected behavior

$ crystal run src/bug1.cr
ERROR: required option: "--prefix"
@at-grandpa
Copy link
Owner

@DannyBen
Thanks!!
Let me think about it.

@at-grandpa
Copy link
Owner

at-grandpa commented May 12, 2020

@DannyBen
released https://github.com/at-grandpa/clim/releases/tag/v0.11.2

The exception message has been fixed to read as follows.

$ crystal run src/bug1.cr
ERROR: Required options. "--prefix <text>"

Please see the `--help`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants