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
# 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[: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)

  begin
    @opts[:index] = Integer(args.first) - 1 if args.first
  rescue ArgumentError
    raise "'#{args.first}' expected to be a preselected index"
  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