I want create a command that has the following structure command path/to/some/file
How do I enable this without entering the option -p or –path?
#!/usr/bin/env ruby
require 'optparse'
options = {}
option = OptionParser.new() do |opts|
opts.on('-p PATH', '--path PATH', 'First path argument') do |path| // How do I enable this without entering the option -p or --path?
options[:path] = path
end
end
option.parse!(ARGV)
It’s not stated very explicitly in the docs, but
OptionParserwill extract all options fromARGVand leave the rest, so the right way is just to useARGVas if it were the list of paths.