ruby - OptionsParser execute methods? -
I'm sorry if this is a clearly obvious question, but the documents of opt-ons are totally horrible and I do not think its I was just a simple question, can I execute a method by using this option:
DNS = new.new option = {} optparse = OptionParser.new do | Opts | opts.banner = $ usage options [: standard] = incorrect opts.on ('a', '-standard', 'standard DNS query') option [[standard] = true end option [: mail] = wrong option [ MX ',' - mail ',' Mx server quarry 'option) options [: mail] = true end option [: reverse] = false opts.on (' ptr ',' --reverse ',' reverse DNS lookup ' ') Option [: reverse] = true end opts.on (' -h ',' --help ',' display use ') opts exit end end option.parse! ARGV.Have | RGR | If option [: mail] dns.ptr_records (arg) if option [: reverse] end / former> it seems that I can not do this , Or I'm doing it wrong. Because in fact this is the only thing printing "querying # {Arg}" string.
Your example works for me almost the only thing you need to change is "-" abbreviated For the names of the options. Ie
opts.on (instead of '-a', '-standard', 'standard DNS queries') instead
opts.on ('a', '-standard', 'standard DNS query') In this way & lt; your_program & gt; Some-A will have the : standard option defined if you place a in opts.on , in your cycle Will be identified as another arg , not as an option.
Comments
Post a Comment