Class: M2A::CLI::Argparse::Argparser
- Inherits:
-
Object
- Object
- M2A::CLI::Argparse::Argparser
- Defined in:
- lib/m2a/cli/argparse.rb
Instance Method Summary collapse
-
#initialize ⇒ Argparser
constructor
A new instance of Argparser.
- #options ⇒ Object
-
#opts ⇒ Object
idempotent.
- #parsed_options! ⇒ Object
- #print_help_and_exit ⇒ Object
Constructor Details
#initialize ⇒ Argparser
Returns a new instance of Argparser.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/m2a/cli/argparse.rb', line 8 def initialize @optparser = OptionParser.new do |opts| opts. = "Usage: ascii_meme <meme_name>" opts.on('-w', '--width WIDTH', Float, "Output WIDTH characters wide") do |width| #{{{ [:width] = width.to_i end #}}} opts.on('-h', '--height HEIGHT', Float, "Output HEIGHT characters high") do |height|#{{{ [:height] = height.to_i end #}}} opts.on('--help', "Print this help screen") do puts opts exit end end end |
Instance Method Details
#options ⇒ Object
47 48 49 |
# File 'lib/m2a/cli/argparse.rb', line 47 def @options ||= Hash.new end |
#opts ⇒ Object
idempotent
27 28 29 |
# File 'lib/m2a/cli/argparse.rb', line 27 def opts @opts ||= end |
#parsed_options! ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/m2a/cli/argparse.rb', line 31 def @optparser.parse! if ARGV.empty? == 0 print_help_and_exit else [:meme] = ARGV.join(" ") end OpenStruct.new() end |
#print_help_and_exit ⇒ Object
42 43 44 45 |
# File 'lib/m2a/cli/argparse.rb', line 42 def print_help_and_exit puts @optparser.help exit end |