Class: EacRubyUtils::Envs::Command
Defined Under Namespace
Modules: ExtraOptions
Classes: ExecuteResult
Constant Summary
Console::Speaker::STDERR, Console::Speaker::STDIN, Console::Speaker::STDOUT
Instance Method Summary
collapse
#chdir, #envvar, #pipe, #status_result
current_node, #fatal_error, #info, #infom, #infov, on_node, #on_speaker_node, #out, pop, push, #puts, #request_input, #success, #title, #warn
Constructor Details
#initialize(env, command, extra_options = {}) ⇒ Command
Returns a new instance of Command.
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 17
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
33
34
35
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 33
def append(args)
duplicate_by_command(@command + args)
end
|
29
30
31
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 29
def args
@command
end
|
#command(options = {}) ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 45
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_pipe(append_envvars(c)))
),
options
)
end
|
#execute(options = {}) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 64
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
56
57
58
59
60
61
62
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 56
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
37
38
39
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 37
def prepend(args)
duplicate_by_command(args + @command)
end
|
#spawn(options = {}) ⇒ Object
74
75
76
77
78
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 74
def spawn(options = {})
c = command(options)
puts "SPAWN: #{c}".light_red if debug?
::EacRubyUtils::Envs::Spawn.new(c)
end
|
#system(options = {}) ⇒ Object
86
87
88
89
90
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 86
def system(options = {})
c = command(options)
puts c.light_red if debug?
Kernel.system(c)
end
|
#system!(options = {}) ⇒ Object
80
81
82
83
84
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 80
def system!(options = {})
return if system(options)
raise "system! command failed: #{self}"
end
|
41
42
43
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 41
def to_s
"#{@command} [ENV: #{@env}]"
end
|