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
- #down ⇒ Object
- #exec(*command) ⇒ Object
- #logs(*services) ⇒ Object
- #run_command(*command) ⇒ Object
- #shell_command ⇒ Object
- #up ⇒ 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.
23 24 25 26 27 28 29 30 |
# File 'lib/wip/cli.rb', line 23 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
18 |
# File 'lib/wip/cli.rb', line 18 def self.exit_on_failure? = true |
Instance Method Details
#build(*extra) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/wip/cli.rb', line 55 def build(*extra) extra.shift if extra.first == '--' settings = load_config.command('build') || {} context = settings['context'] || load_config.defaults['context'] || '.' BuildContext.new(context).stage do |staged_context| execute(builder.build(settings: settings.merge('context' => staged_context), extra: extra)) end end |
#config ⇒ Object
50 51 52 |
# File 'lib/wip/cli.rb', line 50 def config puts YAML.dump(load_config.to_h) end |
#dispatch(name = nil, *arguments) ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'lib/wip/cli.rb', line 129 def dispatch(name = nil, *arguments) raise ConfigError, 'A command is required' unless name values = load_config.command(name) || raise(ConfigError, "Unknown command: #{name}") return dispatch_compose(name, values, arguments) if load_config.compose? execute(builder.custom(name, arguments), interactive: tty?(values.fetch('interactive', false))) end |
#doctor ⇒ Object
43 44 45 46 47 |
# File 'lib/wip/cli.rb', line 43 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 |
#down ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/wip/cli.rb', line 77 def down return execute(compose_bridge.down, exit_on_failure: false) if load_config.compose? execute(builder.down, exit_on_failure: false) execute(builder.remove, exit_on_failure: false) load_config.dependencies.each_key do |name| execute(builder.dependency_down(name), exit_on_failure: false) execute(builder.dependency_remove(name), exit_on_failure: false) end end |
#exec(*command) ⇒ Object
90 91 92 |
# File 'lib/wip/cli.rb', line 90 def exec(*command) execute(exec_target(command, interactive: [:interactive]), interactive: tty?([:interactive])) end |
#logs(*services) ⇒ Object
122 123 124 125 126 |
# File 'lib/wip/cli.rb', line 122 def logs(*services) raise ConfigError, '`wip logs` is only available in compose mode' unless load_config.compose? execute(compose_bridge.logs(services: services, follow: [:follow]), interactive: true) end |
#run_command(*command) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/wip/cli.rb', line 96 def run_command(*command) if load_config.compose? warn "wip: compose mode has no ephemeral 'run'; executing in the running " \ "'#{load_config.compose_service}' service instead" return execute(exec_target(command, interactive: [:interactive]), interactive: tty?([:interactive])) end execute(builder.run(command, interactive: [:interactive]), interactive: tty?([:interactive])) end |
#shell_command ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/wip/cli.rb', line 109 def shell_command configured = load_config.command('shell') return dispatch('shell') if configured code = execute(exec_target(['bash'], interactive: true), interactive: tty?(true), exit_on_failure: false) return if code.zero? execute(exec_target(['sh'], interactive: true), interactive: tty?(true)) end |
#up ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/wip/cli.rb', line 66 def up if load_config.compose? return execute(compose_bridge.up(detach: [:detach]), interactive: tty?(![:detach])) end ensure_network load_config.dependencies.each_key { |name| ensure_dependency(name) } ensure_container end |