Class: Wip::CLI
- Inherits:
-
Thor
- Object
- Thor
- Wip::CLI
- Defined in:
- lib/wip/cli.rb
Overview
Thor-based command-line interface for wip.
Class Method Summary collapse
-
.dispatch(meth, given_args, given_opts, config) ⇒ Object
Thor only falls back to the default task when no command name is given at all; an unrecognized first argument (e.g. a custom wip.yml command name) would otherwise raise "Could not find command".
- .exit_on_failure? ⇒ Boolean
Instance Method Summary collapse
- #build(*extra) ⇒ Object
- #config ⇒ Object
- #dispatch(name = nil, *arguments) ⇒ Object
- #doctor ⇒ Object
- #exec(*command) ⇒ Object
- #run_command(*command) ⇒ Object
- #shell_command ⇒ Object
- #version ⇒ Object
Class Method Details
.dispatch(meth, given_args, given_opts, config) ⇒ Object
Thor only falls back to the default task when no command name is given at
all; an unrecognized first argument (e.g. a custom wip.yml command name)
would otherwise raise "Could not find command". Route those to dispatch.
17 18 19 20 21 22 23 24 |
# File 'lib/wip/cli.rb', line 17 def self.dispatch(meth, given_args, given_opts, config) name = given_args.first if meth.nil? && name && !name.to_s.start_with?('-') && find_command_possibilities(name).empty? return super('dispatch', given_args, given_opts, config) end super end |
.exit_on_failure? ⇒ Boolean
12 |
# File 'lib/wip/cli.rb', line 12 def self.exit_on_failure? = true |
Instance Method Details
#build(*extra) ⇒ Object
49 50 51 52 |
# File 'lib/wip/cli.rb', line 49 def build(*extra) extra.shift if extra.first == '--' execute(builder.build(settings: load_config.command('build') || {}, extra: extra)) end |
#config ⇒ Object
44 45 46 |
# File 'lib/wip/cli.rb', line 44 def config puts YAML.dump(load_config.to_h) end |
#dispatch(name = nil, *arguments) ⇒ Object
78 79 80 81 82 |
# File 'lib/wip/cli.rb', line 78 def dispatch(name = nil, *arguments) raise ConfigError, 'A command is required' unless name execute(builder.custom(name, arguments)) end |
#doctor ⇒ Object
37 38 39 40 41 |
# File 'lib/wip/cli.rb', line 37 def doctor results = Doctor.new(loader: loader).call results.each { |item| puts "[#{item.level.to_s.upcase}] #{item.}" } exit(1) if results.any? { |item| item.level == :fail } end |
#exec(*command) ⇒ Object
56 57 58 |
# File 'lib/wip/cli.rb', line 56 def exec(*command) execute(builder.exec(command, interactive: [:interactive])) end |
#run_command(*command) ⇒ Object
62 63 64 |
# File 'lib/wip/cli.rb', line 62 def run_command(*command) execute(builder.run(command, interactive: [:interactive])) end |
#shell_command ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/wip/cli.rb', line 68 def shell_command configured = load_config.command('shell') return execute(builder.custom('shell', [])) if configured code = execute(builder.exec(['bash'], settings: { 'interactive' => true }, interactive: true)) execute(builder.exec(['sh'], settings: { 'interactive' => true }, interactive: true)) if code != 0 end |