Class: EacRubyUtils::Envs::Command
- Inherits:
-
Object
- Object
- EacRubyUtils::Envs::Command
show all
- Includes:
- Console::Speaker, ExtraOptions
- Defined in:
- lib/eac_ruby_utils/envs/command.rb,
lib/eac_ruby_utils/envs/command/extra_options.rb
Defined Under Namespace
Modules: ExtraOptions
Classes: ExecuteResult
Instance Method Summary
collapse
#chdir, #envvar, #pipe
#fatal_error, #info, #infom, #infov, #out, #puts, #success, #title, #warn
Constructor Details
#initialize(env, command, extra_options = {}) ⇒ Command
Returns a new instance of Command.
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 11
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
27
28
29
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 27
def append(args)
duplicate_by_command(@command + args)
end
|
#args ⇒ Object
23
24
25
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 23
def args
@command
end
|
#command(options = {}) ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 39
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
57
58
59
60
61
62
63
64
65
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 57
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
50
51
52
53
54
55
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 50
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
31
32
33
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 31
def prepend(args)
duplicate_by_command(args + @command)
end
|
#system(options = {}) ⇒ Object
73
74
75
76
77
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 73
def system(options = {})
c = command(options)
puts c.light_red if debug?
Kernel.system(c)
end
|
#system!(options = {}) ⇒ Object
67
68
69
70
71
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 67
def system!(options = {})
return if system(options)
raise "system! command failed: #{self}"
end
|
#to_s ⇒ Object
35
36
37
|
# File 'lib/eac_ruby_utils/envs/command.rb', line 35
def to_s
"#{@command} [ENV: #{@env}]"
end
|