Class: MGit::System::SystemCommand
- Inherits:
-
Object
- Object
- MGit::System::SystemCommand
show all
- Includes:
- Output
- Defined in:
- lib/mgit/system.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Output
#perror, #pinfo, #psystem, #ptable, #pwarn
Constructor Details
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/mgit/system.rb', line 10
def initialize(cmd, opts)
opts, popen_opts = (opts)
@stdout, @stderr, @st = Open3.capture3(cmd, popen_opts)
psystem(stdout.strip) if opts[:print_stdout]
return if success?
psystem(stderr.strip) if opts[:print_stderr]
fail SystemCommandError.new(cmd, opts[:error]) if opts[:raise]
end
|
Instance Attribute Details
#stderr ⇒ Object
Returns the value of attribute stderr.
8
9
10
|
# File 'lib/mgit/system.rb', line 8
def stderr
@stderr
end
|
#stdout ⇒ Object
Returns the value of attribute stdout.
8
9
10
|
# File 'lib/mgit/system.rb', line 8
def stdout
@stdout
end
|
Instance Method Details
#=~(other) ⇒ Object
26
27
28
|
# File 'lib/mgit/system.rb', line 26
def =~(other)
(@stdout =~ other) || (@stderr =~ other)
end
|
#default_options ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/mgit/system.rb', line 30
def default_options
{
print_stdout: false,
print_stderr: false,
raise: false,
error: 'Command failed.'
}
end
|
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/mgit/system.rb', line 39
def (opts)
popen_opts = opts.dup
opts = Hash[
default_options.map do |k, v|
[k, popen_opts.key?(k) ? popen_opts.delete(k) : v]
end
]
[opts, popen_opts]
end
|
#success? ⇒ Boolean
22
23
24
|
# File 'lib/mgit/system.rb', line 22
def success?
@st.exitstatus == 0
end
|