Module: Can::ArgParse

Defined in:
lib/can/argparse.rb

Constant Summary collapse

Version =
VERSION

Class Method Summary collapse

Class Method Details

.get_modeObject



65
66
67
# File 'lib/can/argparse.rb', line 65

def self.get_mode
  ($options & MODES.keys).first || :trash
end

.help_string(mode) ⇒ Object

Returns a mode’s help string



78
79
80
# File 'lib/can/argparse.rb', line 78

def self.help_string (mode)
  ALL_FLAGS[mode][2]
end

.incompatible_opts?Boolean

Sees if $options has incompatible items

Returns:

  • (Boolean)


60
61
62
63
# File 'lib/can/argparse.rb', line 60

def self.incompatible_opts?
  modes = MODES.keys
  ($options & modes).length > 1
end

.init_argsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/can/argparse.rb', line 43

def self.init_args
  OptionParser.new do |opts|
    opts.banner = USAGE

    ALL_FLAGS.each do |mode,v|
      opts.on(short_opt(mode), long_opt(mode), help_string(mode)) do |opt|
        $options << mode
      end
    end
  end.parse!

  if ArgParse.incompatible_opts?
    Error.fatal "Too many mode arguments"
  end
end

.long_opt(mode) ⇒ Object



73
74
75
# File 'lib/can/argparse.rb', line 73

def self.long_opt (mode)
  ALL_FLAGS[mode][1]
end

.short_opt(mode) ⇒ Object



69
70
71
# File 'lib/can/argparse.rb', line 69

def self.short_opt (mode)
  ALL_FLAGS[mode][0]
end

.valid_opt?(opt) ⇒ Boolean

Returns an options’s corresponding mode, if it is valid

Returns:

  • (Boolean)


83
84
85
86
87
88
89
90
# File 'lib/can/argparse.rb', line 83

def self.valid_opt? (opt)
  result = MODES.find { |k,v|
    v[0..2].include? opt
  }
  if result
    result.first
  end
end