Class: SshMenu::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/sshmenu/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Options

Returns a new instance of Options.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sshmenu/options.rb', line 9

def initialize(args)
  @opts = {}
  opt_parser = OptionParser.new do |opts|
    opts.banner = "usage: sshmenu [options] [selected_index]\n"
    opts.banner << "add no arguments to show a list of configured connections"

    opts.on('-e', '--edit', 'edit configuration file') do |e|
      @opts = @opts.merge({:action => :edit})
    end

    opts.on_tail('-v', '--version', 'print version') do
      puts "sshmenu, version #{VERSION}"
      exit
    end

    opts.on_tail('-h', '--help', 'print this help') do
      puts opts
      exit
    end
  end

  opt_parser.parse!(args)

  unless args.first.nil?
    begin
      @opts = @opts.merge({:index => Integer(args.first) - 1})
    rescue ArgumentError
      raise "'#{args[0]}' expected to be a preselected index"
    end
  end
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



7
8
9
# File 'lib/sshmenu/options.rb', line 7

def opts
  @opts
end