ruby-sh 2.1.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.editorconfig +9 -0
- data/.rubocop.yml +2 -2
- data/.ruby-version +1 -0
- data/Gemfile +16 -2
- data/Gemfile.lock +147 -40
- data/README.md +122 -179
- data/Rakefile +4 -5
- data/lib/rubsh/command.rb +7 -10
- data/lib/rubsh/running_command.rb +103 -120
- data/lib/rubsh/version.rb +1 -1
- data/lib/rubsh.rb +8 -3
- data/rubsh.gemspec +3 -3
- metadata +9 -16
- data/.overcommit.yml +0 -26
- data/.rubocop +0 -0
- data/lib/rubsh/running_pipeline.rb +0 -243
- data/lib/rubsh/shell/env.rb +0 -15
- data/lib/rubsh/shell.rb +0 -24
- data/sig/rubsh.rbs +0 -4
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
# Rubsh
|
1
|
+
# Rubsh (a.k.a. ruby-sh)
|
2
2
|
|
3
3
|
Rubsh (a.k.a. ruby-sh) - Inspired by [python-sh], allows you to call any program as if it were a function:
|
4
4
|
|
5
5
|
```ruby
|
6
6
|
require 'rubsh'
|
7
7
|
|
8
|
-
|
9
|
-
print(
|
8
|
+
ifconfig = Rubsh.cmd('ifconfig')
|
9
|
+
print(ifconfig.call('wlan0').stdout_data)
|
10
10
|
```
|
11
11
|
|
12
12
|
Output:
|
@@ -27,40 +27,11 @@ Note that these aren't Ruby functions, these are running the binary commands on
|
|
27
27
|
|
28
28
|
When using this library you can:
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
## Table of Contents
|
38
|
-
|
39
|
-
* [Installation](#installation)
|
40
|
-
* [Usage](#usage)
|
41
|
-
* [Basic Syntax](#basic-syntax)
|
42
|
-
* [Passing Arguments](#passing-arguments)
|
43
|
-
* [Exit Codes](#exit-codes)
|
44
|
-
* [Redirection](#redirection)
|
45
|
-
* [Incremental Iteration](#incremental-iteration)
|
46
|
-
* [Background Processes](#background-processes)
|
47
|
-
* [Baking](#baking)
|
48
|
-
* [Subcommands](#subcommands)
|
49
|
-
* [Piping](#piping)
|
50
|
-
* [Reference](#reference)
|
51
|
-
* [Special Kwargs](#special-kwargs)
|
52
|
-
* [FAQ](#faq)
|
53
|
-
* [Why doesn’t `*` work as a command argument?](#why-doesnt--work-as-a-command-argument)
|
54
|
-
* [How do I execute a bash builtin?](#how-do-i-execute-a-bash-builtin)
|
55
|
-
* [How do I call a program that isn’t in $PATH?](#how-do-i-call-a-program-that-isnt-in-path)
|
56
|
-
* [How do I run a command and connect it to stdout and stdin?](#how-do-i-run-a-command-and-connect-it-to-stdout-and-stdin)
|
57
|
-
* [How do I order keyword arguments?](#how-do-i-order-keyword-arguments)
|
58
|
-
* [Development](#development)
|
59
|
-
* [Contributing](#contributing)
|
60
|
-
* [Acknowledgements](#acknowledgements)
|
61
|
-
* [License](#license)
|
62
|
-
* [Code Of Conduct](#code-of-conduct)
|
63
|
-
|
30
|
+
- Call any program as if it were a function.
|
31
|
+
- Get an exception when exit code is not 0.
|
32
|
+
- Force terminate the process if it does not finish within the timeout.
|
33
|
+
- Always split the shell command into tokens, reduce command injection risk.
|
34
|
+
- etc.
|
64
35
|
|
65
36
|
## Installation
|
66
37
|
|
@@ -72,50 +43,50 @@ gem 'ruby-sh', require: 'rubsh'
|
|
72
43
|
|
73
44
|
And then execute:
|
74
45
|
|
75
|
-
|
46
|
+
```console
|
47
|
+
$ bundle install
|
48
|
+
```
|
76
49
|
|
77
50
|
Or install it yourself as:
|
78
51
|
|
79
|
-
|
80
|
-
|
52
|
+
```console
|
53
|
+
$ gem install ruby-sh
|
54
|
+
```
|
81
55
|
|
82
56
|
## Usage
|
83
57
|
|
84
58
|
### Basic Syntax
|
85
59
|
|
86
60
|
```ruby
|
87
|
-
# Create a
|
88
|
-
|
89
|
-
|
90
|
-
# Create a command, use `command`/`cmd`
|
91
|
-
cmd = sh.cmd("ls")
|
61
|
+
# Create a command
|
62
|
+
ls = Rubsh.cmd("ls")
|
92
63
|
|
93
|
-
# Invoke
|
94
|
-
|
64
|
+
# Invoke it
|
65
|
+
r = ls.call("-la")
|
95
66
|
|
96
67
|
# Print result
|
97
|
-
print
|
68
|
+
print(r.stdout_data)
|
98
69
|
```
|
99
70
|
|
100
71
|
### Passing Arguments
|
101
72
|
|
102
73
|
```ruby
|
103
|
-
|
74
|
+
Rubsh.cmd("ls").call("-l", "/tmp", color: "always", human_readable: true)
|
104
75
|
# => ["/usr/bin/ls", "-l", "/tmp", "--color=always", "--human-readable"]
|
105
76
|
|
106
|
-
|
77
|
+
Rubsh.cmd("curl").call("https://www.ruby-lang.org/", o: "page.html", silent: true)
|
107
78
|
# => ["/usr/bin/curl", "https://www.ruby-lang.org/", "-opage.html", "--silent"]
|
108
79
|
|
109
|
-
|
80
|
+
Rubsh.cmd("git").call(:status, { v: true })
|
110
81
|
# => ["/usr/bin/git", "status", "-v"]
|
111
82
|
|
112
|
-
|
83
|
+
Rubsh.cmd("git").call(:status, { v: true }, "--", ".")
|
113
84
|
# => ["/usr/bin/git", "status", "-v", "--", "."]
|
114
85
|
|
115
|
-
|
86
|
+
Rubsh.cmd("git").call(:status, { v: proc{ true }, short: true }, "--", ".")
|
116
87
|
# => ["/usr/bin/git", "status", "-v", "--short", "--", "."]
|
117
88
|
|
118
|
-
|
89
|
+
Rubsh.cmd("git").call(:status, { v: true }, v: false)
|
119
90
|
# => ["/usr/bin/git", "status"]
|
120
91
|
```
|
121
92
|
|
@@ -123,19 +94,19 @@ sh.cmd("git").call(:status, { v: true }, v: false)
|
|
123
94
|
|
124
95
|
```ruby
|
125
96
|
# Successful
|
126
|
-
r =
|
97
|
+
r = Rubsh.cmd("ls").call("/")
|
127
98
|
r.exit_code # => 0
|
128
99
|
|
129
100
|
# a `CommandReturnFailureError` raised when run failure
|
130
101
|
begin
|
131
|
-
|
102
|
+
Rubsh.cmd("ls").call("/some/non-existant/folder")
|
132
103
|
rescue Rubsh::Exceptions::CommandReturnFailureError => e
|
133
104
|
e.exit_code # => 2
|
134
105
|
end
|
135
106
|
|
136
107
|
# Treats as success use `:_ok_code`
|
137
|
-
r =
|
138
|
-
r =
|
108
|
+
r = Rubsh.cmd("ls").call("/some/non-existant/folder", _ok_code: [0, 1, 2])
|
109
|
+
r = Rubsh.cmd("ls").call("/some/non-existant/folder", _ok_code: 0..2)
|
139
110
|
r.exit_code # => 2
|
140
111
|
```
|
141
112
|
|
@@ -143,29 +114,29 @@ r.exit_code # => 2
|
|
143
114
|
|
144
115
|
```ruby
|
145
116
|
# Filename
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
117
|
+
Rubsh.cmd("ls").call(_out: "/tmp/dir_content")
|
118
|
+
Rubsh.cmd("ls").call(_out: ["/tmp/dir_content", "w"])
|
119
|
+
Rubsh.cmd("ls").call(_out: ["/tmp/dir_content", "w", 0600])
|
120
|
+
Rubsh.cmd("ls").call(_out: ["/tmp/dir_content", File::WRONLY|File::EXCL|File::CREAT, 0600])
|
150
121
|
|
151
122
|
# File object
|
152
|
-
File.open("/tmp/dir_content", "w") { |f|
|
123
|
+
File.open("/tmp/dir_content", "w") { |f| Rubsh.cmd("ls").call(_out: f) }
|
153
124
|
|
154
125
|
# `stdout_data` & `stderr_data`
|
155
|
-
r =
|
126
|
+
r = Rubsh.cmd("sh").call("-c", "echo out; echo err >&2")
|
156
127
|
r.stdout_data # => "out\n"
|
157
128
|
r.stderr_data # => "err\n"
|
158
129
|
|
159
130
|
# Redirects stderr and stderr to the same place use `_err_to_out`
|
160
|
-
r =
|
131
|
+
r = Rubsh.cmd("sh").call("-c", "echo out; echo err >&2", _err_to_out: true)
|
161
132
|
r.stdout_data # => "out\nerr\n"
|
162
133
|
r.stderr_data # => nil
|
163
134
|
|
164
135
|
# Read input from data
|
165
|
-
|
136
|
+
Rubsh.cmd("cat").call(_in_data: "hello").stdout_data # => "hello"
|
166
137
|
|
167
138
|
# Read input from file
|
168
|
-
|
139
|
+
Rubsh.cmd("cat").call(_in: "/some/existant/file")
|
169
140
|
```
|
170
141
|
|
171
142
|
### Incremental Iteration
|
@@ -174,9 +145,9 @@ sh.cmd("cat").call_with(_in: "/some/existant/file")
|
|
174
145
|
# By default, output is line-buffered, so the body of the loop will only run
|
175
146
|
# when your process produces a newline. You can change this by changing the
|
176
147
|
# buffer size of the command’s output with `_out_bufsize`/`_err_bufsize`.
|
177
|
-
tail =
|
178
|
-
tail.
|
179
|
-
print
|
148
|
+
tail = Rubsh.cmd("tail")
|
149
|
+
tail.call("-f", "/var/log/some_log_file.log", _capture: ->(stdout, _stderr) {
|
150
|
+
print(stdout)
|
180
151
|
})
|
181
152
|
```
|
182
153
|
|
@@ -184,123 +155,112 @@ tail.call_with("-f", "/var/log/some_log_file.log", _capture: ->(stdout, _stderr)
|
|
184
155
|
|
185
156
|
```ruby
|
186
157
|
# Blocks
|
187
|
-
|
188
|
-
|
158
|
+
Rubsh.cmd("sleep").call(3)
|
159
|
+
print("...3 seconds later")
|
189
160
|
|
190
161
|
# Doesn't block
|
191
|
-
r =
|
192
|
-
|
162
|
+
r = Rubsh.cmd("sleep").call(3, _bg: true)
|
163
|
+
print("prints immediately!")
|
193
164
|
r.wait()
|
194
|
-
|
165
|
+
print("...and 3 seconds later")
|
195
166
|
|
196
167
|
# Timeout
|
197
|
-
r =
|
198
|
-
|
168
|
+
r = Rubsh.cmd("sleep").call(30, _bg: true)
|
169
|
+
print("prints immediately!")
|
199
170
|
r.wait(timeout: 3)
|
200
|
-
|
171
|
+
print("...and 3 seconds later")
|
201
172
|
```
|
202
173
|
|
203
174
|
### Baking
|
204
175
|
|
205
176
|
```ruby
|
206
|
-
ll =
|
207
|
-
ll.
|
177
|
+
ll = Rubsh.cmd("ls").bake("-l")
|
178
|
+
ll.call("/tmp") # => ["/usr/bin/ls", "-l", "/tmp"]
|
208
179
|
|
209
180
|
# Equivalent
|
210
|
-
|
181
|
+
Rubsh.cmd("ls").call("-l", "/tmp")
|
211
182
|
|
212
183
|
# Calling whoami on a server. this is a lot to type out, especially if you wanted
|
213
184
|
# to call many commands (not just whoami) back to back on the same server resolves
|
214
185
|
# to "/usr/bin/ssh myserver.com -p 1393 whoami"
|
215
|
-
|
186
|
+
Rubsh.cmd('ssh').call("myserver.com", "-p 1393", "whoami")
|
216
187
|
|
217
188
|
# Wouldn't it be nice to bake the common parameters into the ssh command?
|
218
|
-
myserver =
|
219
|
-
myserver.
|
220
|
-
myserver.
|
189
|
+
myserver = Rubsh.cmd('ssh').bake("myserver.com", p: 1393)
|
190
|
+
myserver.call('whoami')
|
191
|
+
myserver.call('pwd')
|
192
|
+
|
193
|
+
# With a special kwarg
|
194
|
+
sleep = Rubsh.cmd('sleep').bake(_timeout: 2)
|
195
|
+
sleep.call(1) # => ok
|
196
|
+
sleep.call(3) # => a `CommandReturnFailureError` raised
|
221
197
|
```
|
222
198
|
|
223
199
|
### Subcommands
|
224
200
|
|
225
201
|
```ruby
|
226
202
|
# Use `bake`
|
227
|
-
gst =
|
203
|
+
gst = Rubsh.cmd("git").bake("status")
|
228
204
|
|
229
|
-
gst.
|
230
|
-
gst.
|
205
|
+
gst.call() # => ["/usr/bin/git", "status"]
|
206
|
+
gst.call("-s") # => ["/usr/bin/git", "status", "-s"]
|
231
207
|
```
|
232
208
|
|
233
|
-
### Piping
|
234
|
-
|
235
|
-
```ruby
|
236
|
-
# Run a series of commands connected by `_pipeline`
|
237
|
-
r = sh.pipeline(_in_data: "hello world") do |pipeline|
|
238
|
-
sh.cmd("cat").call_with(_pipeline: pipeline)
|
239
|
-
sh.cmd("wc").call_with("-c", _pipeline: pipeline)
|
240
|
-
end
|
241
|
-
r.stdout_data # => "11\n"
|
242
|
-
```
|
243
|
-
|
244
|
-
|
245
209
|
## Reference
|
246
210
|
|
247
211
|
### Special Kwargs
|
248
212
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
* `_pipeline`:
|
301
|
-
* use: Specifies the :pipeline.
|
302
|
-
* default value: `nil`
|
303
|
-
|
213
|
+
- `_in_data`:
|
214
|
+
- use: Specifies an argument for the process to use as its standard input data.
|
215
|
+
- default value: `nil`
|
216
|
+
- `_in`:
|
217
|
+
- use: Specifies an argument for the process to use as its standard input.
|
218
|
+
- default value: `nil`
|
219
|
+
- `_out`:
|
220
|
+
- use: Where to redirect STDOUT to.
|
221
|
+
- default value: `nil`
|
222
|
+
- `_err`:
|
223
|
+
- use: Where to redirect STDERR to.
|
224
|
+
- default value: `nil`
|
225
|
+
- `_err_to_out`:
|
226
|
+
- use: If true, duplicate the file descriptor bound to the process’s STDOUT also to STDERR.
|
227
|
+
- default value: `false`
|
228
|
+
- `_capture`:
|
229
|
+
- use: Iterates over STDOUT/STDERR.
|
230
|
+
- default value: `nil`
|
231
|
+
- `_bg`:
|
232
|
+
- use: Runs a command in the background. The command will return immediately, and you will have to run RunningCommand#wait on it to ensure it terminates.
|
233
|
+
- default value: `false`
|
234
|
+
- `_timeout`:
|
235
|
+
- use: How much time, in seconds, we should give the process to complete. If the process does not finish within the timeout, it will be terminated.
|
236
|
+
- default value: `nil`
|
237
|
+
- `_env`:
|
238
|
+
- use: A dictionary defining the only environment variables that will be made accessible to the process. If not specified, the calling process’s environment variables are used.
|
239
|
+
- default value: `nil`
|
240
|
+
- `_cwd`:
|
241
|
+
- use: Current working directory of the process.
|
242
|
+
- default value: `nil`
|
243
|
+
- `_ok_code`:
|
244
|
+
- use: Some misbehaved programs use exit codes other than 0 to indicate success. Set to treats as success.
|
245
|
+
- default value: `[0]`
|
246
|
+
- `_no_out`:
|
247
|
+
- use: Disables STDOUT being internally stored. This is useful for commands that produce huge amounts of output that you don’t need, that would otherwise be hogging memory if stored internally by Rubsh.
|
248
|
+
- default value: `false`
|
249
|
+
- `_no_err`:
|
250
|
+
- use: Disables STDERR being internally stored. This is useful for commands that produce huge amounts of output that you don’t need, that would otherwise be hogging memory if stored internally by Rubsh.
|
251
|
+
- default value: `false`
|
252
|
+
- `_out_bufsize`:
|
253
|
+
- use: The STDOUT buffer size. nil for unbuffered, 0 for line buffered, anything else for a buffer of that amount.
|
254
|
+
- default value: `0`
|
255
|
+
- `_err_bufsize`:
|
256
|
+
- use: The STDERR buffer size. nil for unbuffered, 0 for line buffered, anything else for a buffer of that amount.
|
257
|
+
- default value: `0`
|
258
|
+
- `_long_sep`:
|
259
|
+
- use: This is the character(s) that separate a program’s long argument’s key from the value.
|
260
|
+
- default value: `"="`
|
261
|
+
- `_long_prefix`:
|
262
|
+
- use: This is the character(s) that prefix a long argument for the program being run. Some programs use single dashes, for example, and do not understand double dashes.
|
263
|
+
- default value: `"--"`
|
304
264
|
|
305
265
|
## FAQ
|
306
266
|
|
@@ -311,9 +271,8 @@ Glob expansion is a feature of a shell, like Bash, and is performed by the shell
|
|
311
271
|
### How do I execute a bash builtin?
|
312
272
|
|
313
273
|
```ruby
|
314
|
-
|
315
|
-
rawsh
|
316
|
-
print(rawsh.call_with('echo Hello').stdout_data) # => "Hello\n"
|
274
|
+
rawsh = Rubsh.cmd('bash').bake('-c')
|
275
|
+
print(rawsh.call('echo Hello').stdout_data) # => "Hello\n"
|
317
276
|
```
|
318
277
|
|
319
278
|
### How do I call a program that isn’t in $PATH?
|
@@ -321,16 +280,7 @@ print(rawsh.call_with('echo Hello').stdout_data) # => "Hello\n"
|
|
321
280
|
Use absolute binpath
|
322
281
|
|
323
282
|
```ruby
|
324
|
-
|
325
|
-
sh.cmd('/path/to/command').call()
|
326
|
-
```
|
327
|
-
|
328
|
-
OR Use `Rubsh::Shell::Env#path`
|
329
|
-
|
330
|
-
```ruby
|
331
|
-
sh = Rubsh::Shell.new
|
332
|
-
sh.env.path << "/dir/to/command/"
|
333
|
-
sh.cmd('command').call()
|
283
|
+
Rubsh.cmd('/path/to/command').call()
|
334
284
|
```
|
335
285
|
|
336
286
|
### How do I run a command and connect it to stdout and stdin?
|
@@ -348,36 +298,29 @@ my-command --arg1=val1 arg2 --arg3=val3
|
|
348
298
|
Use:
|
349
299
|
|
350
300
|
```ruby
|
351
|
-
|
352
|
-
sh.cmd('my-command').call_with({ arg1: "val1" }, "args2", { arg3: "val3" })
|
301
|
+
Rubsh.cmd('my-command').call({ arg1: "val1" }, "args2", { arg3: "val3" })
|
353
302
|
```
|
354
303
|
|
355
|
-
|
356
304
|
## Development
|
357
305
|
|
358
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `
|
306
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
359
307
|
|
360
308
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
361
309
|
|
362
|
-
|
363
310
|
## Contributing
|
364
311
|
|
365
312
|
Bug reports and pull requests are welcome on GitHub at https://github.com/souk4711/rubsh. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/souk4711/rubsh/blob/main/CODE_OF_CONDUCT.md).
|
366
313
|
|
367
|
-
|
368
314
|
## Acknowledgements
|
369
315
|
|
370
|
-
|
371
|
-
|
316
|
+
- Special thanks to [python-sh].
|
372
317
|
|
373
318
|
## License
|
374
319
|
|
375
320
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
376
321
|
|
377
|
-
|
378
322
|
## Code of Conduct
|
379
323
|
|
380
324
|
Everyone interacting in the Rubsh project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/souk4711/rubsh/blob/main/CODE_OF_CONDUCT.md).
|
381
325
|
|
382
|
-
|
383
|
-
[python-sh]:https://github.com/amoffat/sh
|
326
|
+
[python-sh]: https://github.com/amoffat/sh
|
data/Rakefile
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
|
-
require "rspec/core/rake_task"
|
5
|
-
|
6
|
-
RSpec::Core::RakeTask.new(:spec)
|
7
4
|
|
8
5
|
require "rubocop/rake_task"
|
9
|
-
|
10
6
|
RuboCop::RakeTask.new
|
11
7
|
|
12
|
-
|
8
|
+
require "rspec/core/rake_task"
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
|
11
|
+
task default: %i[rubocop spec]
|
data/lib/rubsh/command.rb
CHANGED
@@ -6,8 +6,7 @@ module Rubsh
|
|
6
6
|
# When a Command object is called, the result that is returned is a RunningCommand
|
7
7
|
# object, which represents the Command put into an execution state.
|
8
8
|
class Command
|
9
|
-
def initialize(
|
10
|
-
@sh = sh
|
9
|
+
def initialize(prog)
|
11
10
|
@prog = prog.to_s
|
12
11
|
@progpath = resolve_progpath(@prog)
|
13
12
|
@baked_opts = []
|
@@ -18,8 +17,7 @@ module Rubsh
|
|
18
17
|
# @return [RunningCommand] An new instance of RunningCommand with execution state.
|
19
18
|
# @example
|
20
19
|
#
|
21
|
-
#
|
22
|
-
# git = Rubsh::Command.new(sh, "git")
|
20
|
+
# git = Rubsh::Command.new("git")
|
23
21
|
# git.call() # => ["git"]
|
24
22
|
# git.call("") # => ["git", ""]
|
25
23
|
# git.call("status") # => ["git", "status"]
|
@@ -30,24 +28,23 @@ module Rubsh
|
|
30
28
|
# git.call(:status, { v: proc{ true }, short: true }, "--", ".") # => ["git", "status", "-v", "--short=true", "--", "."]
|
31
29
|
# git.call(:status, { untracked_files: "normal" }, "--", ".") # => ["git", "status", "--untracked-files=normal", "--", "."]
|
32
30
|
def call(*args, **kwargs)
|
33
|
-
rcmd = RunningCommand.new(@
|
31
|
+
rcmd = RunningCommand.new(@prog, @progpath, *@baked_opts, *args, **kwargs)
|
34
32
|
rcmd.__run
|
35
33
|
rcmd
|
36
34
|
end
|
37
|
-
alias_method :call_with, :call
|
38
35
|
|
39
36
|
# @param args [String, Symbol, #to_s, Hash]
|
40
37
|
# @param kwargs [Hash]
|
41
38
|
# @return [Command] a new instance of Command with baked options.
|
42
39
|
def bake(*args, **kwargs)
|
43
|
-
cmd = Command.new(@
|
40
|
+
cmd = Command.new(@prog)
|
44
41
|
cmd.__bake!(*@baked_opts, *args, **kwargs)
|
45
42
|
cmd
|
46
43
|
end
|
47
44
|
|
48
45
|
# @return [String]
|
49
|
-
def
|
50
|
-
|
46
|
+
def to_s
|
47
|
+
@progpath
|
51
48
|
end
|
52
49
|
|
53
50
|
# @!visibility private
|
@@ -70,7 +67,7 @@ module Rubsh
|
|
70
67
|
progpath = prog
|
71
68
|
end
|
72
69
|
else
|
73
|
-
|
70
|
+
::ENV["PATH"].split(::File::PATH_SEPARATOR).each do |path|
|
74
71
|
filepath = ::File.join(path, prog)
|
75
72
|
if ::File.executable?(filepath) && ::File.file?(filepath)
|
76
73
|
progpath = filepath
|