Class: Appifier::CLI::MainCommand
- Inherits:
-
Thor
- Object
- Thor
- Appifier::CLI::MainCommand
- Defined in:
- lib/appifier/cli.rb
Overview
The CLI Command structure for Thor
Class Method Summary collapse
-
.exit_on_failure? ⇒ Boolean
callback for managing ARGV errors.
Instance Method Summary collapse
- #collect(template) ⇒ Object
- #generate(template, target = '.') ⇒ Object
-
#initialize(*args) ⇒ MainCommand
constructor
A new instance of MainCommand.
- #retrieve(origin) ⇒ Object
Constructor Details
#initialize(*args) ⇒ MainCommand
Returns a new instance of MainCommand.
13 14 15 16 17 |
# File 'lib/appifier/cli.rb', line 13 def initialize(*args) super @output = Carioca::Registry.get.get_service name: :output @finisher = Carioca::Registry.get.get_service name: :finisher end |
Class Method Details
.exit_on_failure? ⇒ Boolean
callback for managing ARGV errors
20 21 22 |
# File 'lib/appifier/cli.rb', line 20 def self.exit_on_failure? true end |
Instance Method Details
#collect(template) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/appifier/cli.rb', line 118 def collect(template) data = nil begin raise "Options incompatibles --file and --stdin" if [:stdin] and [:file] @output.info "Force mode, rewrite dataset if exist" if [:force] if [:file] Appifier::Actors::Collector.new template: template, dataset: open_yaml(filename: [:file]), force: [:force] @output.info "Getting Dataset from file : #{[:file]} for #{template}" elsif [:stdin] @output.info "Getting Dataset from STDIN for #{template}" begin data = STDIN.readlines.join rescue Interrupt @output.error "Dataset input from STDIN cancelled" @finisher.terminate exit_case: :interrupt end Appifier::Actors::Collector.new template: template, dataset: YAML::load(data), force: [:force] else @output.info "Beginning interactive Dataset input for #{template}" collector = Appifier::Actors::Collector.new template: template, force: [:force] collector.collect end @finisher.terminate exit_case: :quiet_exit rescue RuntimeError => e @output.error e. @finisher.terminate exit_case: :error_exit rescue end end |
#generate(template, target = '.') ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/appifier/cli.rb', line 43 def generate(template, target = '.') root = "#{File.(Appifier::DEFAULT_TEMPLATES_PATH)}/#{template}" unless File::exist? root @output.error "Template not found #{template}" @finisher.terminate exit_case: :error_exit end if File::exist? File::("#{DEFAULT_DATASETS_PATH}/#{template}.yml") then dataset = open_dataset(template: template) @output.info "Dataset file found for #{template}" else begin @output.warn "Dataset file not found for #{template}" if TTY::Prompt.new.yes?("Do you want to collect dataset interactively ?") @output.info "Beginning interactive Dataset input for #{template}" collector = Appifier::Actors::Collector.new template: template collector.collect dataset = open_dataset(template: template) else puts "=> Exiting run 'appifier collect #{template}' for collecting data" puts " (use -S for collecting from STDIN or -f <FILE>) " @finisher.terminate exit_case: :quiet_exit end rescue TTY::Reader::InputInterrupt @output.warn "Command interrupted" @finisher.terminate exit_case: :interrupt end end begin generator = Appifier::Actors::Generator.new template_root: root, target_root: File.(target), dataset: dataset generator.generate dry_run: [:simulate], force: [:force] @finisher.terminate exit_case: :quiet_exit rescue RuntimeError => e @output.error e. @finisher.terminate exit_case: :error_exit end end |
#retrieve(origin) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/appifier/cli.rb', line 88 def retrieve(origin) begin type = [:type].to_sym retriever = Appifier::Actors::Retriever.new type: type, origin: origin results = retriever.get @output.info "Detail of notifications : " unless results[:error].empty? and results[:warn].empty? and results[:cleaned].empty? [:error, :warn].each do |level| results[level].each { |value| @output.send level, "#{level.to_s} : #{value}" } end results[:cleaned].each { |value| @output.ok "cleaned : #{value}" } @finisher.terminate exit_case: :error_exit unless results[:error].empty? @finisher.terminate exit_case: :quiet_exit rescue RuntimeError => e @output.error e. @finisher.terminate exit_case: :error_exit end end |