Class: AwsCsshx::Options

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Options

Returns a new instance of Options.



7
8
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/aws_csshx/options.rb', line 7

def initialize(args)
  super()

  user_home = ENV['HOME']

  @orig_args = args.clone

  @parsed = false
  options = {}

  require 'optparse'
  @opts = OptionParser.new do |o|
      o.banner = "Usage: #{File.basename($0)} <file1> <file2> ..."

      o.separator ""
      o.separator "AWS Options"

      options[:group] = 'default'
      o.on( '-g', '--group group1,group2,group3', Array, 'AWS security group name to use for the csshX sessions (comma separated)' ) do |group|
          options[:group] = group
      end

      o.on( '-i', '--aws-identity <identity>', 'Use this keyfile as your SSH private key' ) do |identity|
          options[:ec2_private_key] = identity
      end

      o.on( '-r', '--aws-region <region>', 'AWS region to query for the csshX sessions (default: us-east-1)' ) do |region|
          options[:aws_region] = region
      end

      o.on( '-H', '--hosts x,y,z', Array, 'Additional hosts to add to the group (comma separated)' ) do |server_list|
          options[:additional_servers] = server_list
      end

      o.separator ""
      o.separator "csshX Options"

      options[:login] = 'root'
      o.on( '-l', '--login <login>', 'User login to use for the csshX sessions (default: root)' ) do ||
          options[:login] = 
      end

      options[:csshx_opts] = ''
      o.on( '-o', '--csshx-opts <csshx_opts>', 'Pass the options listed directly to csshx' ) do |csshx_opts|
          options[:csshx_opts] = csshx_opts
      end

      options[:iterm2] = false
      o.on( '-2', '--iterm2', 'Use csshX.iterm instead of csshx' ) do |iterm2|
          options[:iterm2] = true
      end

      o.separator ""

      options[:conf] = "#{Etc.getpwuid.dir}/.csshrc"
      o.on( '-c', '--conf <file>', 'aws_csshX config file (default: .csshrc)' ) do |file|
          if File.exists?(file)
              options[:conf] = file
          else
              raise FileDoesNotExist, "Config file #{file} cannot be found."
          end
      end

      o.on('-V', '--version', "Display version information") do
          options[:version] = true
      end

      options[:help] = false
      o.on( '-h', '--help', 'Display this help screen' ) do
          options[:help] = true
      end

      o.separator ""
      o.separator "Examples:"
      o.separator "  Cluster SSH to all machines in the 'utility' security group:"
      o.separator "    #{File.basename($0)} -g utility"
      o.separator ""
  end

  begin
      @opts.parse!(args)
      self[:options] = options
  rescue OptionParser::InvalidOption => e
      self[:invalid_argument] = e.message
      @opts.parse(args, flags={ :delete_invalid_opts => true })
      self[:options] = options
  end
  @parsed = true
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



5
6
7
# File 'lib/aws_csshx/options.rb', line 5

def opts
  @opts
end

#orig_argsObject (readonly)

Returns the value of attribute orig_args.



5
6
7
# File 'lib/aws_csshx/options.rb', line 5

def orig_args
  @orig_args
end

#parsedObject (readonly)

Returns the value of attribute parsed.



5
6
7
# File 'lib/aws_csshx/options.rb', line 5

def parsed
  @parsed
end

Instance Method Details

#parsed?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/aws_csshx/options.rb', line 97

def parsed?
  @parsed
end