class Safedep::OptionParser
Attributes
configuration[R]
Public Class Methods
new(configuration = Configuration.new)
click to toggle source
# File lib/safedep/cli/option_parser.rb, line 9 def initialize(configuration = Configuration.new) @configuration = configuration setup end
Public Instance Methods
parse(args)
click to toggle source
# File lib/safedep/cli/option_parser.rb, line 14 def parse(args) args = args.dup parser.parse!(args) args end
Private Instance Methods
command_name()
click to toggle source
# File lib/safedep/cli/option_parser.rb, line 48 def command_name File.basename($PROGRAM_NAME) end
define_option(*options, &block)
click to toggle source
# File lib/safedep/cli/option_parser.rb, line 33 def define_option(*options, &block) long_option = options.find { |option| option.start_with?('--') }.split(' ').first description_lines = descriptions[long_option] parser.on(*options, *description_lines, &block) end
descriptions()
click to toggle source
# File lib/safedep/cli/option_parser.rb, line 52 def descriptions @descriptions ||= { '--without' => [ 'Specify groups to skip modification as comma-separated list.' ], '--version' => [ "Show #{command_name} version." ] } end
parser()
click to toggle source
# File lib/safedep/cli/option_parser.rb, line 39 def parser @parser ||= begin banner = "Usage: #{command_name} [options]\n\n" summary_width = 32 # Default indentation = ' ' * 2 ::OptionParser.new(banner, summary_width, indentation) end end
setup()
click to toggle source
# File lib/safedep/cli/option_parser.rb, line 22 def setup define_option('--without GROUP[,GROUP...]') do |arg| configuration.skipped_groups = arg.split(',') end define_option('--version') do puts Version.to_s exit end end