Module: Rubysh
- Defined in:
- lib/rubysh.rb,
lib/rubysh/fd.rb,
lib/rubysh/pipe.rb,
lib/rubysh/util.rb,
lib/rubysh/error.rb,
lib/rubysh/runner.rb,
lib/rubysh/command.rb,
lib/rubysh/version.rb,
lib/rubysh/pipeline.rb,
lib/rubysh/redirect.rb,
lib/rubysh/subprocess.rb,
lib/rubysh/base_command.rb,
lib/rubysh/base_directive.rb,
lib/rubysh/triple_less_than.rb
Defined Under Namespace
Modules: Error, Plugin, Util
Classes: BaseCommand, BaseDirective, Command, FD, Pipe, Pipeline, Redirect, Runner, Subprocess, TripleLessThan
Constant Summary
collapse
- VERSION =
'0.2.4'
Class Method Summary
collapse
-
.<(target = (t=true; nil), opts = (o=true; nil)) ⇒ Object
-
.<<(fd = (f=true; nil), opts = (o=true; nil)) ⇒ Object
-
.>(target = (t=true; nil), opts = (o=true; nil)) ⇒ Object
-
.>>(target = (t=true; nil), opts = (o=true; nil)) ⇒ Object
-
.assert(fact, msg, hard = false) ⇒ Object
-
.check_call(*args, &blk) ⇒ Object
-
.Command(*args) ⇒ Object
-
.FD(*args) ⇒ Object
-
.handle_redirect_args(target, target_omitted, opts, opts_omitted) ⇒ Object
-
.log ⇒ Object
Internal utility methods.
-
.Pipeline(*args) ⇒ Object
-
.run(*args, &blk) ⇒ Object
-
.run_async(*args, &blk) ⇒ Object
-
.stderr ⇒ Object
-
.stdin ⇒ Object
-
.stdout ⇒ Object
Class Method Details
.<(target = (t=true; nil), opts = (o=true; nil)) ⇒ Object
145
146
147
148
149
150
|
# File 'lib/rubysh.rb', line 145
def self.<(target=(t=true; nil), opts=(o=true; nil))
target, opts = handle_redirect_args(target, t, opts, o)
target ||= :stdin
Redirect.new(0, '<', target, opts)
end
|
.<<(fd = (f=true; nil), opts = (o=true; nil)) ⇒ Object
153
154
155
156
157
158
|
# File 'lib/rubysh.rb', line 153
def self.<<(fd=(f=true; nil), opts=(o=true; nil))
fd, opts = handle_redirect_args(fd, f, opts, o)
fd ||= FD.new(0)
TripleLessThan::Shell.new(fd, opts)
end
|
.>(target = (t=true; nil), opts = (o=true; nil)) ⇒ Object
131
132
133
134
135
136
|
# File 'lib/rubysh.rb', line 131
def self.>(target=(t=true; nil), opts=(o=true; nil))
target, opts = handle_redirect_args(target, t, opts, o)
target ||= :stdout
Redirect.new(1, '>', target, opts)
end
|
.>>(target = (t=true; nil), opts = (o=true; nil)) ⇒ Object
138
139
140
141
142
143
|
# File 'lib/rubysh.rb', line 138
def self.>>(target=(t=true; nil), opts=(o=true; nil))
target, opts = handle_redirect_args(target, t, opts, o)
target ||= :stdout
Redirect.new(1, '>>', target, opts)
end
|
.assert(fact, msg, hard = false) ⇒ Object
170
171
172
173
174
175
176
177
|
# File 'lib/rubysh.rb', line 170
def self.assert(fact, msg, hard=false)
return if fact
msg = msg ? "Assertion Failure: #{msg}" : "Assertion Failure"
formatted = "#{msg}\n #{caller.join("\n ")}"
log.error(formatted)
raise msg if hard
end
|
.check_call(*args, &blk) ⇒ Object
102
103
104
105
|
# File 'lib/rubysh.rb', line 102
def self.check_call(*args, &blk)
command = Rubysh::Command.new(args)
command.check_call(&blk)
end
|
.Command(*args) ⇒ Object
107
108
109
|
# File 'lib/rubysh.rb', line 107
def self.Command(*args)
Command.new(*args)
end
|
.FD(*args) ⇒ Object
115
116
117
|
# File 'lib/rubysh.rb', line 115
def self.FD(*args)
FD.new(*args)
end
|
.handle_redirect_args(target, target_omitted, opts, opts_omitted) ⇒ Object
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/rubysh.rb', line 179
def self.handle_redirect_args(target, target_omitted, opts, opts_omitted)
if opts_omitted && target.kind_of?(Hash)
opts = target
opts_omitted = target_omitted
target = nil
target_omitted = true
end
if !target_omitted && !target
raise Rubysh::Error::BaseError.new("You provided #{target.inspect} as your redirect target. This probably indicates a bug in your code. Either omit the target argument or provide a non-false-y value for it.")
end
return target, opts
end
|
.log ⇒ Object
161
162
163
164
165
166
167
168
|
# File 'lib/rubysh.rb', line 161
def self.log
unless @log
@log = Logger.new(STDERR)
@log.level = Logger::WARN
end
@log
end
|
.Pipeline(*args) ⇒ Object
111
112
113
|
# File 'lib/rubysh.rb', line 111
def self.Pipeline(*args)
Pipeline.new(*args)
end
|
.run(*args, &blk) ⇒ Object
92
93
94
95
|
# File 'lib/rubysh.rb', line 92
def self.run(*args, &blk)
command = Rubysh::Command.new(args)
command.run(&blk)
end
|
.run_async(*args, &blk) ⇒ Object
97
98
99
100
|
# File 'lib/rubysh.rb', line 97
def self.run_async(*args, &blk)
command = Rubysh::Command.new(args)
command.run_async(&blk)
end
|
.stderr ⇒ Object
127
128
129
|
# File 'lib/rubysh.rb', line 127
def self.stderr
FD.new(2)
end
|
.stdin ⇒ Object
119
120
121
|
# File 'lib/rubysh.rb', line 119
def self.stdin
FD.new(0)
end
|
.stdout ⇒ Object
123
124
125
|
# File 'lib/rubysh.rb', line 123
def self.stdout
FD.new(1)
end
|