Skip to content

fix(option): create value from default#5

Merged
devnote-dev merged 1 commit intodevnote-dev:mainfrom
snacks02:fix-default
Jan 6, 2023
Merged

fix(option): create value from default#5
devnote-dev merged 1 commit intodevnote-dev:mainfrom
snacks02:fix-default

Conversation

@snacks02
Copy link
Copy Markdown
Contributor

@snacks02 snacks02 commented Jan 6, 2023

How to reproduce:

require "./src/cli"

class MainCmd < CLI::Command
  def setup : Nil
    add_option 'i', "input", default: "out", has_value: true, required: true
  end

  def run(args, options) : Nil
    pp options.get!("input")
  end
end

main = MainCmd.new
main.execute ARGV

Without the fix:

Unhandled exception: Nil assertion failed (NilAssertionError)
  from /usr/lib/crystal/nil.cr:108:5 in 'not_nil!'
  from src/cli/option.cr:85:7 in 'get!'
  from test.cr:12:8 in 'run'
  from src/cli/executor.cr:58:7 in 'handle'
  from src/cli/command.cr:178:7 in 'execute'
  from test.cr:17:1 in '__crystal_main'
  from /usr/lib/crystal/crystal/main.cr:115:5 in 'main_user_code'
  from /usr/lib/crystal/crystal/main.cr:101:7 in 'main'
  from /usr/lib/crystal/crystal/main.cr:127:3 in 'main'
  from /usr/lib/libc.so.6 in '??'
  from /usr/lib/libc.so.6 in '__libc_start_main'
  from ../sysdeps/x86_64/start.S:117 in '_start'
  from ???

With the fix:

CLI::Value(@raw="out")

@devnote-dev devnote-dev merged commit 4455523 into devnote-dev:main Jan 6, 2023
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 this pull request may close these issues.

2 participants