Sha256: 70a2ef01ea84a82ce90273b95aa94ad8bee545028674e9725ff5812677721f46

Contents?: true

Size: 1.91 KB

Versions: 28

Compression:

Stored size: 1.91 KB

Contents

#!/usr/bin/env ruby

$LOAD_PATH << File.join(__dir__, '..', 'lib')

require 'optparse'
require 'ostruct'
require 'tape'

options = OpenStruct.new
opt_parser = OptionParser.new do |opts|
  opts.banner = "Usage: tape <module> <action> [options]"

  opts.on("-v", "--[no-]verbose", "Be loud") {|v| options.verbose = v}

  opts.on("-i", "--inventory [INVENTORY_FILE]",
    String, "Do actions with the given inventory file") do |i|
      options.inventory_file = i
    end

  opts.on('-n', "--name [NAME]",
    String, "The name of the machine to operate on") do |n|
      options.name = n
    end

  opts.on('-p', "--port [PORT]",
    Integer, "The port that the machine is listening on for SSH connections") do |p|
      options.port = p
    end

  opts.on("-h", "--help", "Show this help") do
    STDERR.puts opts
    exit 0
  end

  opts.on("-l", "--limit [PATTERN]",
    String, "Limits ansible runs to hosts matching PATTERN") do |p|
      options.host_pattern = p
    end

  opts.on("-t", "--tags [TAGS]",
    String, "only run plays and tasks tagged with these values") do |t|
      options.tags = t
    end

  opts.separator ''
  opts.separator "MODULES"
  TapeBoxer.registered_modules.values.each do |exec_module|
    opts.separator "  #{exec_module.name.to_s.upcase}"
    exec_module.klass.actions.values.each do |action|
      opts.separator "    #{action.name}: #{action.description}"
    end
  end
end


opt_parser.parse!(ARGV)

fail_without = ->(&block){
  val = block.call

  if val
    return val
  else
    STDERR.puts(opt_parser.help)
    exit 1
  end
}

module_name = fail_without.call{ ARGV.shift }.to_sym
action_name = fail_without.call{ ARGV.shift }.to_sym

exec_module = fail_without.call{TapeBoxer.registered_modules[module_name]}

begin
  exec_module.klass.new(options).execute_action(action_name)
rescue TapeBoxer::InvalidAction,
  TapeBoxer::ActionError, TapeBoxer::UnspecifiedOption => e

  STDERR.puts(e.message)
  exit 2
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
taperole-1.4.3 bin/tape
taperole-1.4.2 bin/tape
taperole-1.4.1 bin/tape
taperole-1.4.0 bin/tape
taperole-1.3.6 bin/tape
taperole-1.3.5 bin/tape
taperole-1.3.4 bin/tape
taperole-1.3.3 bin/tape
taperole-1.3.2 bin/tape
taperole-1.3.1 bin/tape
taperole-1.3.0 bin/tape
taperole-1.2.8 bin/tape
taperole-1.2.7 bin/tape
taperole-1.2.6 bin/tape
taperole-1.2.5 bin/tape
taperole-1.2.4 bin/tape
taperole-1.2.3 bin/tape
taperole-1.2.2 bin/tape
taperole-1.2.1 bin/tape
taperole-1.2.0 bin/tape