Class: MiniCli::Instance::ArgvParser

Inherits:
Object
  • Object
show all
Defined in:
lib/mini-cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(helptext, args) ⇒ ArgvParser

Returns a new instance of ArgvParser.



133
134
135
136
137
138
# File 'lib/mini-cli.rb', line 133

def initialize(helptext, args)
  @helptext = helptext.to_s
  @args = args.flatten.map!(&:to_s).uniq
  @options = nil
  @show_options_text = true
end

Instance Method Details

#parse(argv, error) ⇒ Object



150
151
152
153
154
# File 'lib/mini-cli.rb', line 150

def parse(argv, error)
  @error, @result = error, {}
  parse_help! unless @options
  process(parse_argv(argv))
end

#show_help(name) ⇒ Object



140
141
142
143
144
145
146
147
148
# File 'lib/mini-cli.rb', line 140

def show_help(name)
  parse_help! unless @options
  print("Usage: #{name}")
  print(' [<options>]') unless @options.empty?
  print(' ', @args.join(' ')) unless @args.empty?
  puts
  puts(nil, 'Options:') if @show_options_text
  puts(@helptext.gsub('<*name*>', name)) unless @helptext.empty?
end