Class: Rubish::Command
Constant Summary
UnixExecutable::EIO
Instance Attribute Summary collapse
Attributes inherited from Executable
#working_directory
Instance Method Summary
collapse
#exec, #exec!
Methods inherited from Executable
#awk, #cd, #each, #each!, #err, #err=, #exec, #exec!, #first, #head, #i, #i=, #io, #last, #map, #map!, #o, #o=, #sed, #tail
Constructor Details
#initialize(cmd, args) ⇒ Command
Returns a new instance of Command.
6
7
8
9
10
|
# File 'lib/rubish/command.rb', line 6
def initialize(cmd,args)
@quoted = false
@args = args
@cmd = cmd.to_s
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
4
5
6
|
# File 'lib/rubish/command.rb', line 4
def args
@args
end
|
#cmd ⇒ Object
Returns the value of attribute cmd.
4
5
6
|
# File 'lib/rubish/command.rb', line 4
def cmd
@cmd
end
|
#quoted ⇒ Object
if true, arguments for exec are not shell expanded.
5
6
7
|
# File 'lib/rubish/command.rb', line 5
def quoted
@quoted
end
|
Instance Method Details
#%(arg) ⇒ Object
68
69
70
71
|
# File 'lib/rubish/command.rb', line 68
def %(arg)
@args = [arg]
self
end
|
#+(arg) ⇒ Object
63
64
65
66
|
# File 'lib/rubish/command.rb', line 63
def +(arg)
@args << arg
self
end
|
#exec_with(i, o, e) ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/rubish/command.rb', line 12
def exec_with(i,o,e)
normalize_args!
unless pid = Kernel.fork
system_exec(i,o,e)
else
return [pid]
end
end
|
#normalize_args!(args = @args) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/rubish/command.rb', line 73
def normalize_args!(args=@args)
args.map! do |arg|
case arg
when Symbol
"-#{arg.to_s[0..-1]}"
when Array
normalize_args!(arg)
when String
arg
else
raise "argument to command should be one of Symbol, String, Array "
end
end
args.flatten!
args
end
|
#q ⇒ Object
53
54
55
56
|
# File 'lib/rubish/command.rb', line 53
def q
@quoted = true
self
end
|
#q! ⇒ Object
58
59
60
61
|
# File 'lib/rubish/command.rb', line 58
def q!
@quoted = false
self
end
|
#system_exec(i, o, e) ⇒ Object
this method should be called after fork
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/rubish/command.rb', line 23
def system_exec(i,o,e)
begin
Rubish.set_stdioe(i,o,e)
if self.quoted
Kernel.exec self.cmd, *args
else
Kernel.exec "#{self.cmd} #{args.join " "}"
end
rescue
Process.exit!(1)
end
end
|
#to_s ⇒ Object
49
50
51
|
# File 'lib/rubish/command.rb', line 49
def to_s
self.inspect
end
|