Class: Dip::Commands::Run
- Inherits:
-
Dip::Command
- Object
- Dip::Command
- Dip::Commands::Run
- Defined in:
- lib/dip/commands/run.rb
Instance Method Summary collapse
-
#execute ⇒ Object
TODO: Refactor rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
-
#initialize(cmd, subcmd = nil, argv = [], run_vars: nil) ⇒ Run
constructor
A new instance of Run.
-
#prepare_compose_run_options(value) ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength.
- #run_vars ⇒ Object
Methods inherited from Dip::Command
Constructor Details
#initialize(cmd, subcmd = nil, argv = [], run_vars: nil) ⇒ Run
Returns a new instance of Run.
10 11 12 13 14 15 16 |
# File 'lib/dip/commands/run.rb', line 10 def initialize(cmd, subcmd = nil, argv = [], run_vars: nil) @cmd = cmd.to_sym @subcmd = subcmd.to_sym if subcmd @argv = argv @run_vars = run_vars @config = ::Dip.config.interaction end |
Instance Method Details
#execute ⇒ Object
TODO: Refactor rubocop:disable Metrics/AbcSize, Metrics/MethodLength
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 |
# File 'lib/dip/commands/run.rb', line 20 def execute command = @config.fetch(@cmd) command[:subcommands] ||= {} if (subcommand = command[:subcommands].fetch(@subcmd, {})).any? subcommand[:command] ||= nil command.merge!(subcommand) elsif @subcmd @argv.unshift(@subcmd.to_s) end Dip.env.merge(command[:environment]) if command[:environment] compose_method = command.fetch(:compose_method, "run").to_s compose_argv = [] compose_argv.concat((command[:compose_run_options])) compose_argv.concat(run_vars) compose_argv << "--rm" if compose_method == "run" compose_argv << command.fetch(:service).to_s compose_argv += command[:command].to_s.shellsplit compose_argv.concat(@argv) Dip::Commands::Compose.new(compose_method, compose_argv).execute end |
#prepare_compose_run_options(value) ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength
47 48 49 50 51 52 53 54 |
# File 'lib/dip/commands/run.rb', line 47 def (value) return [] unless value value.map do |o| o = o.start_with?("-") ? o : "--#{o}" o.shellsplit end.flatten end |
#run_vars ⇒ Object
56 57 58 59 60 |
# File 'lib/dip/commands/run.rb', line 56 def run_vars return [] unless @run_vars @run_vars.map { |k, v| ["-e", "#{k}=#{v}"] }.flatten end |