I am trying to use optionparse of ruby to parse the arguments to my ruby script. Problem is when I am running the script like this bundler exec ruby generation.rb --help I am getting error "uninitialized constant OpenStruct (NameError)"
I believe since I am running the script using bundle exec I should not be getting this error. What am I doing wrong.
require 'optparse'
def parse(args)
options = OpenStruct.new
options.dir = '../somerepo'
opts = OptionParser.new do |opts|
opts.banner = "Usage: generation.rb [options]"
opts.separator ""
opts.separator "Options:"
opts.on("--temp c_name", "abcddd") { |abc|
options.temp = abc
}
opts.separator ""
opts.on_tail("-h", "--help", "Show this message") {
puts opts
exit
}
opts.parse!(args)
return options
end
end
inputOpts = parse(ARGV)
You should require OpenStruct
source manually:
require 'ostruct'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With