module Cfer::Auster::CLI
Public Class Methods
apply()
click to toggle source
# File lib/cfer/auster/cli/apply.rb, line 9 def self.apply Cri::Command.define do name "apply" usage "apply aws-region/config-set count-or-tag" description "Applies this Auster step against your AWS infrastructure." CLI.standard_options(self) run do |opts, args, cmd| if args.length < 2 puts cmd.help exit 1 else CLI.repo_from_options(opts) do |repo| args = args.dup config_set = repo.config_set(args.shift) step = repo.step_by_count_or_tag(args.shift) step.apply(config_set) end end end end end
base_options(cmd)
click to toggle source
# File lib/cfer/auster/cli/_shared.rb, line 8 def self.base_options(cmd) cmd.instance_eval do flag :v, :verbose, "sets logging to DEBUG" do |_, _| Cfer::Auster::Logging.logger.level = Logger::DEBUG end end end
destroy()
click to toggle source
# File lib/cfer/auster/cli/destroy.rb, line 9 def self.destroy Cri::Command.define do name "destroy" usage "destroy aws-region/config-set count-or-tag" description "Destroys this Auster step in your AWS account." CLI.standard_options(self) run do |opts, args, cmd| if args.length < 2 puts cmd.help exit 1 else CLI.repo_from_options(opts) do |repo| args = args.dup config_set = repo.config_set(args.shift) step = repo.step_by_count_or_tag(args.shift) step.destroy(config_set) end end end end end
execute(args)
click to toggle source
# File lib/cfer/auster/cli.rb, line 59 def self.execute(args) CLI.root.run(args) end
generate()
click to toggle source
# File lib/cfer/auster/cli/generate.rb, line 10 def self.generate ret = Cri::Command.define do name "generate" description "Encapsulates generators for Auster." CLI.base_options(self) flag :h, :help, "show help for this command" do |_, cmd| puts cmd.help Kernel.exit 0 end run do |_, _, cmd| puts cmd.help Kernel.exit 0 end end ret.add_command(CLI.generate_repo) ret.add_command(CLI.generate_step) ret end
generate_repo()
click to toggle source
# File lib/cfer/auster/cli/generate/repo.rb, line 7 def self.generate_repo Cri::Command.define do name "repo" usage "repo OUTPUT_PATH" description "Generates a new Auster plan repo." CLI.base_options(self) flag :h, :help, "show help for this command" do |_, cmd| puts cmd.help Kernel.exit 0 end run do |_, _, cmd| raise "TODO: implement" end end end
generate_step()
click to toggle source
# File lib/cfer/auster/cli/generate/step.rb, line 7 def self.generate_step Cri::Command.define do name "step" usage "step ##" description "Generates a step in the current Auster repo." CLI.base_options(self) flag :h, :help, "show help for this command" do |_, cmd| puts cmd.help Kernel.exit 0 end run do |_, _, cmd| raise "TODO: implement" end end end
json()
click to toggle source
# File lib/cfer/auster/cli/json.rb, line 9 def self.json Cri::Command.define do name "json" usage "json aws-region/config-set count-or-tag" description "Generates the CloudFormation JSON for this step." CLI.standard_options(self) option :o, :"output-file", "Saves the JSON output to a file (otherwise prints to stdout)", argument: :required run do |opts, args, cmd| if args.length < 2 puts cmd.help exit 1 else CLI.repo_from_options(opts) do |repo| args = args.dup config_set = repo.config_set(args.shift) step = repo.step_by_count_or_tag(args.shift) ret = step.json(config_set) if opts[:"output-file"] IO.write(opts[:"output-file"], ret) else puts ret end end end end end end
nuke()
click to toggle source
# File lib/cfer/auster/cli/nuke.rb, line 9 def self.nuke Cri::Command.define do extend Cfer::Auster::Logging::Mixin name "nuke" usage "nuke aws-region/config-set" description "Destroys ALL AWS RESOURCES related to this config set." CLI.standard_options(self) flag nil, :force, "bypasses confirmation - use with care!" run do |opts, args, cmd| if args.length < 1 puts cmd.help exit 1 else CLI.repo_from_options(opts) do |repo| args = args.dup config_set = repo.config_set(args.shift) accepted = !!opts[:force] if !accepted && $stdin.tty? $stderr.write "\n\n" $stderr.write "!!! YOU ARE ABOUT TO DO SOMETHING VERY DRASTIC! !!!\n" $stderr.write "You are requesting to destroy ALL STEPS of the config set '#{config_set.full_name}'.\n" $stderr.write "If you are certain you wish to do this, please type CONFIRM: " input = $stdin.readline.chomp if input != "CONFIRM" $stderr.write "\n\nInvalid input. Aborting nuke.\n\n" Kernel.exit 1 end accepted = true end unless accepted logger.error "You must pass interactive confirmation or use the --force parameter to nuke." Kernel.exit 1 end repo.nuke(config_set) logger.warn "I really, really hope you meant to do that." end end end end end
repo_from_options(opts, &block)
click to toggle source
# File lib/cfer/auster/cli/_shared.rb, line 35 def self.repo_from_options(opts, &block) require "cfer/auster/repo" repo = if opts[:"plan-path"] Cfer::Auster::Repo.new(opts[:"plan-path"]) else Cfer::Auster::Repo.discover_from_cwd end block.call(repo) end
root()
click to toggle source
# File lib/cfer/auster/cli.rb, line 19 def self.root ret = Cri::Command.define do name "auster" description "The best way to manage CloudFormation. Ever. (We think.)" CLI.base_options(self) flag :h, :help, "show help for this command" do |_, cmd| puts cmd.help Kernel.exit 0 end flag nil, :version, "show version information for this command" do |_, _| puts Cfer::Auster::VERSION Kernel.exit 0 end flag nil, :"version-json", "show version information for this command in JSON" do |_, _| puts JSON.pretty_generate( Semantic::Version.new(Cfer::Auster::VERSION).to_h.reject { |_, v| v.nil? } ) Kernel.exit 0 end run do |_, _, cmd| puts cmd.help Kernel.exit 0 end end ret.add_command(CLI.generate) ret.add_command(CLI.json) ret.add_command(CLI.task) ret.add_command(CLI.tasks) ret.add_command(CLI.apply) ret.add_command(CLI.destroy) ret.add_command(CLI.nuke) ret end
standard_options(cmd)
click to toggle source
# File lib/cfer/auster/cli/_shared.rb, line 16 def self.standard_options(cmd) cmd.instance_eval do CLI.base_options(cmd) flag :h, :help, "show help for this command" do |_, cmd| puts cmd.help Kernel.exit 0 end option :l, :"log-level", "Configures the verbosity of the Auster and Cfer loggers. (default: info)", argument: :required option :p, :"plan-path", "The path to the Auster plan repo that should be used (otherwise searches from pwd)", argument: :required end end
task()
click to toggle source
# File lib/cfer/auster/cli/task.rb, line 9 def self.task Cri::Command.define do name "task" usage "task aws-region/config-set script-name [args]" description "Runs a task within the context of an Auster config set." CLI.standard_options(self) run do |opts, args, cmd| if args.length < 2 puts cmd.help exit 1 else CLI.repo_from_options(opts) do |repo| args = args.dup config_set = repo.config_set(args.shift) task_name = args.shift repo.run_task(task_name, config_set, args) end end end end end
tasks()
click to toggle source
# File lib/cfer/auster/cli/tasks.rb, line 9 def self.tasks Cri::Command.define do name "tasks" usage "tasks" description "Prints a list of tasks available in this repo." CLI.standard_options(self) run do |opts, args, cmd| CLI.repo_from_options(opts) do |repo| repo.tasks.each { |t| puts t } end end end end