Class: EacRubyUtils::Envs::Command
- Inherits:
-
Object
- Object
- EacRubyUtils::Envs::Command
show all
- Defined in:
- lib/eac_ruby_utils/envs/command.rb,
lib/eac_ruby_utils/envs/command/concat.rb,
lib/eac_ruby_utils/envs/command/envvars.rb,
lib/eac_ruby_utils/envs/command/extra_options.rb
Defined Under Namespace
Modules: Concat, Envvars, ExtraOptions
Classes: ExecuteResult
Instance Method Summary
collapse
Constructor Details
#initialize(env, command, extra_options = {}) ⇒ Command
Returns a new instance of Command.
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 15
def initialize(env, command, = {})
@env = env
@extra_options = .with_indifferent_access
if command.count == 1 && command.first.is_a?(Array)
@command = command.first
elsif command.is_a?(Array)
@command = command
else
raise "Invalid argument command: #{command}|#{command.class}"
end
end
|
Instance Method Details
#append(args) ⇒ Object
31
32
33
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 31
def append(args)
duplicate_by_command(@command + args)
end
|
27
28
29
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 27
def args
@command
end
|
#command(options = {}) ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 43
def command(options = {})
c = @command
c = c.map { |x| escape(x) }.join(' ') if c.is_a?(Enumerable)
append_command_options(
@env.command_line(
append_chdir(append_concat(append_envvars(c)))
),
options
)
end
|
#execute(options = {}) ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 62
def execute(options = {})
c = command(options)
puts "BEFORE: #{c}".light_red if debug?
t1 = Time.now
r = ::EacRubyUtils::Envs::Process.new(c).to_h
i = Time.now - t1
puts "AFTER [#{i}]: #{c}".light_red if debug?
r
end
|
#execute!(options = {}) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 54
def execute!(options = {})
options[:exit_outputs] = status_results.merge(options[:exit_outputs].presence || {})
er = ExecuteResult.new(execute(options), options)
return er.result if er.success?
raise "execute! command failed: #{self}\n#{er.r.pretty_inspect}"
end
|
#prepend(args) ⇒ Object
35
36
37
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 35
def prepend(args)
duplicate_by_command(args + @command)
end
|
#spawn(options = {}) ⇒ Object
72
73
74
75
76
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 72
def spawn(options = {})
c = command(options)
puts "SPAWN: #{c}".light_red if debug?
::EacRubyUtils::Envs::Spawn.new(c)
end
|
#system(options = {}) ⇒ Object
84
85
86
87
88
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 84
def system(options = {})
c = command(options)
puts c.light_red if debug?
Kernel.system(c)
end
|
#system!(options = {}) ⇒ Object
78
79
80
81
82
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 78
def system!(options = {})
return if system(options)
raise "system! command failed: #{self}"
end
|
39
40
41
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 39
def to_s
"#{@command} [ENV: #{@env}]"
end
|