Module: Amigrind::CLI

Defined in:
lib/amigrind/cli.rb,
lib/amigrind/cli/_root.rb,
lib/amigrind/cli/_helpers.rb,
lib/amigrind/cli/repo/init.rb,
lib/amigrind/cli/build/execute.rb,
lib/amigrind/cli/inventory/list.rb,
lib/amigrind/cli/repo/_category.rb,
lib/amigrind/cli/blueprints/list.rb,
lib/amigrind/cli/blueprints/show.rb,
lib/amigrind/cli/build/_category.rb,
lib/amigrind/cli/environments/list.rb,
lib/amigrind/cli/environments/show.rb,
lib/amigrind/cli/build/print_packer.rb,
lib/amigrind/cli/inventory/_category.rb,
lib/amigrind/cli/inventory/get-image.rb,
lib/amigrind/cli/blueprints/_category.rb,
lib/amigrind/cli/environments/_category.rb,
lib/amigrind/cli/inventory/add_to_channel.rb,
lib/amigrind/cli/inventory/remove_from_channel.rb

Constant Summary collapse

ROOT =

credentials = Amigrind::Core::CredentialsHelper.from_cli_options(options)

Cri::Command.define do
  name    File.basename($PROGRAM_NAME, ".*")
  summary "the best way to build AMIs for AWS"

  flag :h, :help, 'show help for this command' do |_, cmd|
    puts cmd.help
    exit 0
  end

  flag :v, :verbose, "debug logging instead of info" do |_, _|
    Amigrind::Core::Logging.log_level(:debug)
  end

  flag :q, :quiet, "warn logging instead of info" do |_, _|
    Amigrind::Core::Logging.log_level(:warn)
  end

  flag nil, :version, "show application version" do |_, _|
    require 'json'

    versions = {
      'amigrind' => Amigrind::VERSION,
      'amigrind-core' => Amigrind::Core::VERSION,
      'aws-sdk' => Aws::VERSION,
      'packer' => File.which('packer').nil? ? nil : `packer --version`.strip
    }

    puts JSON.pretty_generate versions

    Kernel.exit 0
  end

  run do |_, _, cmd|
    puts cmd.help
    exit 0
  end
end
REPO =
Cri::Command.define do
  name        'repo'
  description 'commands related to managing and creating Amigrind repos'

  run do |_, _, cmd|
    puts cmd.help
    exit 0
  end
end
BUILD =
Cri::Command.define do
  name        'build'
  description 'commands related to building AMIs for consumption'

  run do |_, _, cmd|
    puts cmd.help
    exit 0
  end
end
INVENTORY =
Cri::Command.define do
  name        'inventory'
  description 'commands related to the current Amigrind AMI inventory'

  run do |_, _, cmd|
    puts cmd.help
    exit 0
  end
end
BLUEPRINTS =
Cri::Command.define do
  name        'blueprints'
  description 'commands related to Amigrind blueprints in your Amigrind repo'

  run do |_, _, cmd|
    puts cmd.help
    exit 0
  end
end
ENVIRONMENTS =
Cri::Command.define do
  name        'environments'
  description 'commands related to Amigrind environments in your Amigrind repo'

  run do |_, _, cmd|
    puts cmd.help
    exit 0
  end
end

Class Method Summary collapse

Class Method Details

.blueprint_options(cmd) ⇒ Object



22
23
24
25
26
# File 'lib/amigrind/cli/_helpers.rb', line 22

def blueprint_options(cmd)
  cmd.option  nil, :blueprint,
              'name of the blueprint in the Amigrind repo',
              argument: :required
end

.channel_options(cmd) ⇒ Object



28
29
30
31
32
# File 'lib/amigrind/cli/_helpers.rb', line 28

def channel_options(cmd)
  cmd.option  nil, :channel,
              'channel to use, from the selected Amigrind environment',
              argument: :required
end

.environment_name_parse(opts) ⇒ Object



34
35
36
37
38
# File 'lib/amigrind/cli/_helpers.rb', line 34

def environment_name_parse(opts)
  opts[:environment] ||
    (Amigrind::Config['amigrind'] || {})['default_environment'] ||
    'default'
end

.environment_options(cmd) ⇒ Object



16
17
18
19
20
# File 'lib/amigrind/cli/_helpers.rb', line 16

def environment_options(cmd)
  cmd.option  nil, :environment,
              'name of the environment in the Amigrind repo',
              argument: :required
end

.output_format_options(cmd) ⇒ Object



4
5
6
7
8
# File 'lib/amigrind/cli/_helpers.rb', line 4

def output_format_options(cmd)
  cmd.option  :f, :format,
              'output format',
              argument: :required
end

.repo_options(cmd) ⇒ Object



10
11
12
13
14
# File 'lib/amigrind/cli/_helpers.rb', line 10

def repo_options(cmd)
  cmd.option  nil, :'repo-path',
              'path to the Amigrind repo',
              argument: :required
end

.run(args) ⇒ Object



8
9
10
# File 'lib/amigrind/cli.rb', line 8

def self.run(args)
  ROOT.run(args)
end

.with_repo_and_env(opts, &block) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/amigrind/cli/_helpers.rb', line 40

def with_repo_and_env(opts, &block)
  Amigrind::Repo.with_repo(path: opts[:'repo-path']) do |repo|
    env_name = CLI.environment_name_parse(opts)

    block.call(repo, repo.environment(env_name))
  end
end