Module: Browserctl::Commands::Workflow
- Extended by:
- CliOutput
- Defined in:
- lib/browserctl/commands/workflow.rb
Constant Summary collapse
- USAGE =
"Usage: browserctl workflow <run|list|describe> [args]"
Class Method Summary collapse
- .run(runner, args) ⇒ Object
- .run_describe(runner, args) ⇒ Object
- .run_list(runner) ⇒ Object
- .run_workflow(runner, args) ⇒ Object
Methods included from CliOutput
Class Method Details
.run(runner, args) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/browserctl/commands/workflow.rb', line 13 def self.run(runner, args) sub = args.shift or abort USAGE case sub when "run" then run_workflow(runner, args) when "list" then run_list(runner) when "describe" then run_describe(runner, args) else abort "unknown workflow subcommand '#{sub}'\n#{USAGE}" end end |
.run_describe(runner, args) ⇒ Object
59 60 61 62 |
# File 'lib/browserctl/commands/workflow.rb', line 59 def self.run_describe(runner, args) name = args.shift or abort "usage: browserctl workflow describe <name>" puts JSON.pretty_generate(runner.describe_workflow(name)) end |
.run_list(runner) ⇒ Object
54 55 56 57 |
# File 'lib/browserctl/commands/workflow.rb', line 54 def self.run_list(runner) list = runner.list_workflows puts JSON.generate({ workflows: list.map { |w| { name: w[:name], desc: w[:desc] } } }) end |
.run_workflow(runner, args) ⇒ Object
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 |
# File 'lib/browserctl/commands/workflow.rb', line 23 def self.run_workflow(runner, args) name = args.shift or abort "usage: browserctl workflow run <name|file> [--params file] [--key value ...]" if File.exist?(name) before = Browserctl.registry_snapshot.keys load File.(name) name = (Browserctl.registry_snapshot.keys - before).first || File.basename(name, ".rb") end params_file_idx = args.index("--params") file_params = {} if params_file_idx params_path = args.delete_at(params_file_idx + 1) args.delete_at(params_file_idx) begin file_params = Browserctl::Runner.load_params_file(params_path) rescue StandardError => e abort "Error loading params file: #{e.}" end end cli_params = {} args.each_slice(2) do |flag, val| key = flag.sub(/\A--/, "").to_sym cli_params[key] = val end params = file_params.merge(cli_params) success = runner.run_workflow(name, **params) exit(success ? 0 : 1) end |