class Simulacrum::CLI::Parser
Option parser for handling options passed into the Simulacrum
CLI
This class is mostly borrowed from Cane's Parser
class. Thanks Xav! <3
Attributes
stdout[R]
Public Class Methods
new(stdout = $stdout)
click to toggle source
# File lib/simulacrum/cli/parser.rb, line 22 def initialize(stdout = $stdout) @stdout = stdout add_banner add_format_options add_separator add_version add_help end
parse(args)
click to toggle source
# File lib/simulacrum/cli/parser.rb, line 18 def self.parse(args) new.parse(args) end
Public Instance Methods
parse(args, _return = true)
click to toggle source
# File lib/simulacrum/cli/parser.rb, line 32 def parse(args, _return = true) parser.parse!(args) options['files'] = args if args.size > 0 OpenStruct.new(default_options.merge(options)) rescue OptionParser::InvalidOption, OptionParser::AmbiguousOption args = %w(--help) _return = false retry rescue OptionsHandled _return end
Private Instance Methods
add_format_options()
click to toggle source
# File lib/simulacrum/cli/parser.rb, line 74 def add_format_options parser.on('-c', '--[no-]color', '--[no-]colour', 'Enable color in the output.') do |value| options['color'] = value end parser.on('-v', '--verbose', 'Be more shouty.') do |value| options['verbose'] = value end end
add_help()
click to toggle source
# File lib/simulacrum/cli/parser.rb, line 67 def add_help parser.on_tail('-h', '--help', 'You\'re looking at it!') do stdout.puts parser fail OptionsHandled end end
add_separator()
click to toggle source
# File lib/simulacrum/cli/parser.rb, line 56 def add_separator parser.separator '' end
add_version()
click to toggle source
# File lib/simulacrum/cli/parser.rb, line 60 def add_version parser.on_tail('--version', 'Show version') do stdout.puts Simulacrum::VERSION fail OptionsHandled end end
default_options()
click to toggle source
# File lib/simulacrum/cli/parser.rb, line 47 def default_options {} end
options()
click to toggle source
# File lib/simulacrum/cli/parser.rb, line 89 def options @options ||= begin options = {} options['files'] = ['spec/ui'] options['color'] = false options['verbose'] = false options end end
parser()
click to toggle source
# File lib/simulacrum/cli/parser.rb, line 99 def parser @parser ||= OptionParser.new end