Class: Butcher::Stab::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/butcher/stab/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ CLI

Returns a new instance of CLI.



4
5
6
7
8
9
10
11
12
# File 'lib/butcher/stab/cli.rb', line 4

def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel)
  self.argv = argv
  self.stdin = stdin
  self.stdout = stdout
  self.stderr = stderr
  self.kernel = kernel
  self.options = {}
  optparse
end

Instance Attribute Details

#argvObject

Returns the value of attribute argv.



2
3
4
# File 'lib/butcher/stab/cli.rb', line 2

def argv
  @argv
end

#kernelObject

Returns the value of attribute kernel.



2
3
4
# File 'lib/butcher/stab/cli.rb', line 2

def kernel
  @kernel
end

#optionsObject

Returns the value of attribute options.



2
3
4
# File 'lib/butcher/stab/cli.rb', line 2

def options
  @options
end

#stderrObject

Returns the value of attribute stderr.



2
3
4
# File 'lib/butcher/stab/cli.rb', line 2

def stderr
  @stderr
end

#stdinObject

Returns the value of attribute stdin.



2
3
4
# File 'lib/butcher/stab/cli.rb', line 2

def stdin
  @stdin
end

#stdoutObject

Returns the value of attribute stdout.



2
3
4
# File 'lib/butcher/stab/cli.rb', line 2

def stdout
  @stdout
end

Instance Method Details

#execute!Object



14
15
16
17
18
19
# File 'lib/butcher/stab/cli.rb', line 14

def execute!
  return stdout.puts(usage) if options[:help]
  raise Butcher::Stab::UsageError.new(usage) if node_name.nil?

  ssh_to(matching_node)
end

#node_nameObject



21
22
23
# File 'lib/butcher/stab/cli.rb', line 21

def node_name
  @node_name ||= argv.shift
end

#usageObject



25
26
27
28
29
30
31
32
# File 'lib/butcher/stab/cli.rb', line 25

def usage
  <<-END.gsub(/^ {6}/, '')
    Usage: stab [options] <node name> [ssh options]
      -f    --force       # download new node list even if a cache file exists
      -v    --verbose     # be expressive
      -h    --help        # print this info
  END
end