Chris911
Chris911

Reputation: 4199

OptionParser throwing 'Missing Argument' for no reasons

I only have 1 possible option and it is parsed as following:

  def parse_options
    options = {}
    options[:markdown] = false
    OptionParser.new do |opts|
      opts.on('-md', '--markdown', 'Use Markdown Syntax') do
        options[:markdown] = true
      end
    end.parse!
  end

As you can see the option doesn't require any argument. What I find even stranger is this works:

command -md

but this throws the exception:

command --markdown

in `parse_options': missing argument: --markdown (OptionParser::MissingArgument)

Any ideas? I read the doc and multiple examples but can't figure it out.

Upvotes: 2

Views: 2405

Answers (1)

Sandy Vanderbleek
Sandy Vanderbleek

Reputation: 1132

You can't use a two letter switch like that. With

opts.on('-m', '--markdown', 'Use Markdown Syntax') do

it works fine. See Short style switch under OptionParser documentation

Upvotes: 4

Related Questions