Class: Bow::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/bow/application.rb

Constant Summary collapse

'Usage: bow command arguments [options]'.freeze
COLUMN_WIDTH =
32
EMPTY_COLUMN =
(' ' * COLUMN_WIDTH).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Application

Returns a new instance of Application.



11
12
13
14
15
16
17
18
19
20
# File 'lib/bow/application.rb', line 11

def initialize(argv)
  @options = {
    user: 'root',
    group: 'all',
    inventory: 'hosts.json'
  }
  @argv = argv.dup
  @ssh_helpers = {}
  @debug = false
end

Instance Attribute Details

#argvObject

Returns the value of attribute argv.



9
10
11
# File 'lib/bow/application.rb', line 9

def argv
  @argv
end

#debugObject

Returns the value of attribute debug.



9
10
11
# File 'lib/bow/application.rb', line 9

def debug
  @debug
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/bow/application.rb', line 9

def options
  @options
end

Instance Method Details

#configObject



40
41
42
# File 'lib/bow/application.rb', line 40

def config
  Config
end

#debug?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/bow/application.rb', line 53

def debug?
  !!@debug
end

#inventoryObject

rubocop:enable Lint/ShadowingOuterLocalVariable



34
35
36
37
38
# File 'lib/bow/application.rb', line 34

def inventory
  return @inventory if @inventory
  @inventory ||= Inventory.new
  @inventory.ensure!
end

#runObject

rubocop:disable Lint/ShadowingOuterLocalVariable



23
24
25
26
27
28
29
30
31
# File 'lib/bow/application.rb', line 23

def run
  opts = OptionParser.new do |opts|
    opts.banner = build_banner
    options_parser.parse(opts)
  end
  opts.parse!(argv)
  command = parse_arguments(opts)
  command.run
end

#ssh_helper(host) ⇒ Object



44
45
46
47
# File 'lib/bow/application.rb', line 44

def ssh_helper(host)
  conn = host.conn
  @ssh_helpers[conn] ||= SshHelper.new(conn, self)
end

#targets(user) ⇒ Object



49
50
51
# File 'lib/bow/application.rb', line 49

def targets(user)
  @targets ||= Targets.new(inventory.targetfile, user)
end