Module: Cfer::Auster::CLI
- Defined in:
- lib/cfer/auster/cli.rb,
lib/cfer/auster/cli/json.rb,
lib/cfer/auster/cli/nuke.rb,
lib/cfer/auster/cli/task.rb,
lib/cfer/auster/cli/apply.rb,
lib/cfer/auster/cli/tasks.rb,
lib/cfer/auster/cli/_shared.rb,
lib/cfer/auster/cli/destroy.rb,
lib/cfer/auster/cli/generate.rb,
lib/cfer/auster/cli/generate/repo.rb,
lib/cfer/auster/cli/generate/step.rb
Class Method Summary collapse
- .apply ⇒ Object
- .base_options(cmd) ⇒ Object
- .destroy ⇒ Object
- .execute(args) ⇒ Object
- .generate ⇒ Object
- .generate_repo ⇒ Object
- .generate_step ⇒ Object
- .json ⇒ Object
- .nuke ⇒ Object
- .repo_from_options(opts, &block) ⇒ Object
- .root ⇒ Object
- .standard_options(cmd) ⇒ Object
- .task ⇒ Object
- .tasks ⇒ Object
Class Method Details
.apply ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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.(self) run do |opts, args, cmd| if args.length < 2 puts cmd.help exit 1 else CLI.(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) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/cfer/auster/cli/_shared.rb', line 8 def self.(cmd) cmd.instance_eval do flag :v, :verbose, "sets logging to DEBUG" do |_, _| Cfer::Auster::Logging.logger.level = Logger::DEBUG end end end |
.destroy ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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.(self) run do |opts, args, cmd| if args.length < 2 puts cmd.help exit 1 else CLI.(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) ⇒ Object
59 60 61 |
# File 'lib/cfer/auster/cli.rb', line 59 def self.execute(args) CLI.root.run(args) end |
.generate ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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.(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 ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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.(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 ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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.(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 ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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.(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.(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 ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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.(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.(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) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cfer/auster/cli/_shared.rb', line 35 def self.(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 ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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.(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) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cfer/auster/cli/_shared.rb', line 16 def self.(cmd) cmd.instance_eval do CLI.(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 ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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.(self) run do |opts, args, cmd| if args.length < 2 puts cmd.help exit 1 else CLI.(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 ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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.(self) run do |opts, args, cmd| CLI.(opts) do |repo| repo.tasks.each { |t| puts t } end end end end |