Class: EacRubyUtils::Envs::Command
- Inherits:
-
Object
- Object
- EacRubyUtils::Envs::Command
show all
- Includes:
- Console::Speaker
- Defined in:
- lib/eac_ruby_utils/envs/command.rb
Defined Under Namespace
Classes: ExecuteResult
Instance Method Summary
collapse
#fatal_error, #info, #infov, #out, #puts, #success, #title, #warn
Constructor Details
#initialize(env, command) ⇒ Command
Returns a new instance of Command.
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 6
def initialize(env, command)
@env = env
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
17
18
19
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 17
def append(args)
self.class.new(@env, @command + args)
end
|
#command(options = {}) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 29
def command(options = {})
c = @command
c = c.map { |x| escape(x) }.join(' ') if c.is_a?(Enumerable)
c = @env.command_line(c)
append_command_options(c, options)
end
|
#execute(options = {}) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 42
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
36
37
38
39
40
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 36
def execute!(options = {})
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
21
22
23
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 21
def prepend(args)
self.class.new(@env, args + @command)
end
|
#system(options = {}) ⇒ Object
57
58
59
60
61
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 57
def system(options = {})
c = command(options)
puts c.light_red if debug?
Kernel.system(c)
end
|
#system!(options = {}) ⇒ Object
52
53
54
55
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 52
def system!(options = {})
return if system(options)
raise "system! command failed: #{self}"
end
|
#to_s ⇒ Object
25
26
27
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 25
def to_s
"#{@command} [ENV: #{@env}]"
end
|