tty-command 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/LICENSE.txt +1 -1
- data/README.md +44 -44
- data/lib/tty-command.rb +1 -1
- data/lib/tty/command.rb +18 -18
- data/lib/tty/command/child_process.rb +9 -9
- data/lib/tty/command/cmd.rb +11 -11
- data/lib/tty/command/dry_runner.rb +3 -3
- data/lib/tty/command/exit_error.rb +1 -1
- data/lib/tty/command/printers/abstract.rb +8 -10
- data/lib/tty/command/printers/null.rb +1 -4
- data/lib/tty/command/printers/pretty.rb +10 -15
- data/lib/tty/command/printers/progress.rb +3 -8
- data/lib/tty/command/printers/quiet.rb +3 -7
- data/lib/tty/command/process_runner.rb +25 -17
- data/lib/tty/command/truncator.rb +3 -3
- data/lib/tty/command/version.rb +1 -1
- metadata +20 -68
- data/Rakefile +0 -10
- data/bin/console +0 -6
- data/bin/setup +0 -6
- data/examples/bash.rb +0 -12
- data/examples/basic.rb +0 -9
- data/examples/buffer.rb +0 -4
- data/examples/env.rb +0 -9
- data/examples/logger.rb +0 -10
- data/examples/output.rb +0 -10
- data/examples/pty.rb +0 -9
- data/examples/redirect_stderr.rb +0 -10
- data/examples/redirect_stdin.rb +0 -15
- data/examples/redirect_stdout.rb +0 -10
- data/examples/stdin_input.rb +0 -10
- data/examples/threaded.rb +0 -14
- data/examples/timeout.rb +0 -11
- data/examples/timeout_input.rb +0 -12
- data/examples/wait.rb +0 -21
- data/spec/spec_helper.rb +0 -78
- data/spec/unit/binmode_spec.rb +0 -29
- data/spec/unit/cmd_spec.rb +0 -152
- data/spec/unit/dry_run_spec.rb +0 -42
- data/spec/unit/exit_error_spec.rb +0 -25
- data/spec/unit/input_spec.rb +0 -13
- data/spec/unit/output_spec.rb +0 -25
- data/spec/unit/printer_spec.rb +0 -50
- data/spec/unit/printers/custom_spec.rb +0 -48
- data/spec/unit/printers/null_spec.rb +0 -36
- data/spec/unit/printers/pretty_spec.rb +0 -172
- data/spec/unit/printers/progress_spec.rb +0 -45
- data/spec/unit/printers/quiet_spec.rb +0 -71
- data/spec/unit/pty_spec.rb +0 -62
- data/spec/unit/redirect_spec.rb +0 -103
- data/spec/unit/result_spec.rb +0 -64
- data/spec/unit/ruby_spec.rb +0 -20
- data/spec/unit/run_spec.rb +0 -159
- data/spec/unit/test_spec.rb +0 -11
- data/spec/unit/timeout_spec.rb +0 -36
- data/spec/unit/truncator_spec.rb +0 -73
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-command.gemspec +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efe5adcd3fe993ed0b35a1d640b77e50d42611e4c87efd296656c82680bbe19e
|
4
|
+
data.tar.gz: 91276213aee2b1a56b3b983e3779d47da9c2de4b2f16fd9fa1603173d12ec522
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d3159b1a53f1649a220c6cd41f00fe8c9621c26460715d2352c1ff010c84de2f8ced1a06ce4de998da16f43a9d254429b37f825a370059dad1828b820c28060
|
7
|
+
data.tar.gz: '094d9b3afbc63cb7b94888873e602badf0dc2dd6dee3c2a13c79d2865ee7c1270f52136df5472c9c080f1f157778808033ffe3a4989b72cba6dbcf5d83d57c3c'
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.10.0] - 2020-10-22
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Change :chdir option to escape directory location path
|
7
|
+
* Change gemspec to add metadata and remove test artefacts
|
8
|
+
* Change to update pastel dependency and restrict version to minor only
|
9
|
+
* Remove bundler as a dev dependency and relax rspec's upper boundary
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
* Fix Ruby 2.7 keyword conversion errors
|
13
|
+
* Fix error when environment variable contains % character
|
14
|
+
|
3
15
|
## [v0.9.0] - 2019-09-28
|
4
16
|
|
5
17
|
### Changed
|
@@ -128,6 +140,7 @@
|
|
128
140
|
|
129
141
|
* Initial implementation and release
|
130
142
|
|
143
|
+
[v0.10.0]: https://github.com/piotrmurach/tty-command/compare/v0.9.0...v0.10.0
|
131
144
|
[v0.9.0]: https://github.com/piotrmurach/tty-command/compare/v0.8.2...v0.9.0
|
132
145
|
[v0.8.2]: https://github.com/piotrmurach/tty-command/compare/v0.8.1...v0.8.2
|
133
146
|
[v0.8.1]: https://github.com/piotrmurach/tty-command/compare/v0.8.0...v0.8.1
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2016 Piotr Murach
|
3
|
+
Copyright (c) 2016 Piotr Murach (https://piotrmurach.com)
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
<div align="center">
|
2
|
-
<a href="https://
|
2
|
+
<a href="https://ttytoolkit.org"><img width="130" src="https://github.com/piotrmurach/tty/blob/master/images/tty.png" alt="TTY Toolkit logo"/></a>
|
3
3
|
</div>
|
4
4
|
|
5
5
|
# TTY::Command [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
|
@@ -36,7 +36,7 @@ Why should we be handcuffed to `sh` or `bash` for these scripts when we could be
|
|
36
36
|
Add this line to your application's Gemfile:
|
37
37
|
|
38
38
|
```ruby
|
39
|
-
gem
|
39
|
+
gem "tty-command"
|
40
40
|
```
|
41
41
|
|
42
42
|
And then execute:
|
@@ -88,11 +88,11 @@ Or install it yourself as:
|
|
88
88
|
Create a command instance and then run some commands:
|
89
89
|
|
90
90
|
```ruby
|
91
|
-
require
|
91
|
+
require "tty-command"
|
92
92
|
|
93
93
|
cmd = TTY::Command.new
|
94
|
-
cmd.run(
|
95
|
-
cmd.run(
|
94
|
+
cmd.run("ls -la")
|
95
|
+
cmd.run("echo Hello!")
|
96
96
|
```
|
97
97
|
|
98
98
|
Note that `run` will throw an exception if the command fails. This is already an improvement over ordinary shell scripts, which just keep on going when things go bad. That usually makes things worse.
|
@@ -100,7 +100,7 @@ Note that `run` will throw an exception if the command fails. This is already an
|
|
100
100
|
You can use the return value to capture stdout and stderr:
|
101
101
|
|
102
102
|
```ruby
|
103
|
-
out, err = cmd.run(
|
103
|
+
out, err = cmd.run("cat ~/.bashrc | grep alias")
|
104
104
|
```
|
105
105
|
|
106
106
|
Instead of using a plain old string, you can break up the arguments and they'll get escaped if necessary:
|
@@ -127,13 +127,13 @@ The `env`, `command` and `options` arguments are described in the following sect
|
|
127
127
|
For example, to display file contents:
|
128
128
|
|
129
129
|
```ruby
|
130
|
-
cmd.run(
|
130
|
+
cmd.run("cat file.txt")
|
131
131
|
```
|
132
132
|
|
133
133
|
If the command succeeds, a `TTY::Command::Result` is returned that records stdout and stderr:
|
134
134
|
|
135
135
|
```ruby
|
136
|
-
out, err = cmd.run(
|
136
|
+
out, err = cmd.run("date")
|
137
137
|
puts "The date is #{out}"
|
138
138
|
# => "The date is Tue 10 May 2016 22:30:15 BST\n"
|
139
139
|
```
|
@@ -141,7 +141,7 @@ puts "The date is #{out}"
|
|
141
141
|
You can also pass a block that gets invoked anytime stdout and/or stderr receive output:
|
142
142
|
|
143
143
|
```ruby
|
144
|
-
cmd.run(
|
144
|
+
cmd.run("long running script") do |out, err|
|
145
145
|
output << out if out
|
146
146
|
errors << err if err
|
147
147
|
end
|
@@ -161,8 +161,8 @@ If the error output is very long, the stderr may contain only a prefix, number o
|
|
161
161
|
If you expect a command to fail occasionally, use `run!` instead. Then you can detect failures and respond appropriately. For example:
|
162
162
|
|
163
163
|
```ruby
|
164
|
-
if cmd.run!(
|
165
|
-
cmd.run(
|
164
|
+
if cmd.run!("which xyzzy").failure?
|
165
|
+
cmd.run("brew install xyzzy")
|
166
166
|
end
|
167
167
|
```
|
168
168
|
|
@@ -184,7 +184,7 @@ cmd = TTY::Command.new(printer: :progress)
|
|
184
184
|
By default the printers log to `stdout` but this can be changed by passing an object that responds to `<<` message:
|
185
185
|
|
186
186
|
```ruby
|
187
|
-
logger = Logger.new(
|
187
|
+
logger = Logger.new("dev.log")
|
188
188
|
cmd = TTY::Command.new(output: logger)
|
189
189
|
```
|
190
190
|
|
@@ -206,7 +206,7 @@ By default, when logging is enabled and `pretty` printer is used, each log entry
|
|
206
206
|
|
207
207
|
```ruby
|
208
208
|
cmd = TTY::Command.new(uuid: false)
|
209
|
-
cmd.run(
|
209
|
+
cmd.run("rm -R all_my_files")
|
210
210
|
# =>
|
211
211
|
# Running rm -r all_my_files
|
212
212
|
# ...
|
@@ -230,13 +230,13 @@ When using a command that can fail, setting `:only_output_on_error` option to `t
|
|
230
230
|
|
231
231
|
```ruby
|
232
232
|
cmd = TTY::Command.new
|
233
|
-
cmd.run(
|
233
|
+
cmd.run("non_failing_command", only_output_on_error: true)
|
234
234
|
```
|
235
235
|
|
236
236
|
This will only print the `Running` and `Finished` lines, while:
|
237
237
|
|
238
238
|
```ruby
|
239
|
-
cmd.run(
|
239
|
+
cmd.run("non_failing_command")
|
240
240
|
```
|
241
241
|
|
242
242
|
will also print any output that the `non_failing_command` might generate.
|
@@ -244,13 +244,13 @@ will also print any output that the `non_failing_command` might generate.
|
|
244
244
|
Running either:
|
245
245
|
|
246
246
|
```ruby
|
247
|
-
cmd.run(
|
247
|
+
cmd.run("failing_command", only_output_on_error: true)
|
248
248
|
```
|
249
249
|
|
250
250
|
either:
|
251
251
|
|
252
252
|
```ruby
|
253
|
-
cmd.run(
|
253
|
+
cmd.run("failing_command")
|
254
254
|
```
|
255
255
|
|
256
256
|
will also print the output.
|
@@ -271,7 +271,7 @@ Sometimes it can be useful to put your script into a "dry run" mode that prints
|
|
271
271
|
|
272
272
|
```ruby
|
273
273
|
cmd = TTY::Command.new(dry_run: true)
|
274
|
-
cmd.run(:rm,
|
274
|
+
cmd.run(:rm, "all_my_files")
|
275
275
|
# => [123abc] (dry run) rm all_my_files
|
276
276
|
```
|
277
277
|
|
@@ -286,7 +286,7 @@ cmd.dry_run? # => true
|
|
286
286
|
If you need to wait for a long running script and stop it when a given pattern has been matched use `wait` like so:
|
287
287
|
|
288
288
|
```ruby
|
289
|
-
cmd.wait
|
289
|
+
cmd.wait "tail -f /var/log/production.log", /something happened/
|
290
290
|
```
|
291
291
|
|
292
292
|
### 2.6 Test
|
@@ -294,7 +294,7 @@ cmd.wait 'tail -f /var/log/production.log', /something happened/
|
|
294
294
|
To simulate classic bash test command you case use `test` method with expression to check as a first argument:
|
295
295
|
|
296
296
|
```ruby
|
297
|
-
if cmd.test
|
297
|
+
if cmd.test "-e /etc/passwd"
|
298
298
|
puts "Sweet..."
|
299
299
|
else
|
300
300
|
puts "Ohh no! Where is it?"
|
@@ -317,19 +317,19 @@ cmd.ruby %q{-e "puts 'Hello world'"}
|
|
317
317
|
The environment variables need to be provided as hash entries, that can be set directly as a first argument:
|
318
318
|
|
319
319
|
```ruby
|
320
|
-
cmd.run({
|
320
|
+
cmd.run({"RAILS_ENV" => "PRODUCTION"}, :rails, "server")
|
321
321
|
```
|
322
322
|
|
323
323
|
or as an option with `:env` key:
|
324
324
|
|
325
325
|
```ruby
|
326
|
-
cmd.run(:rails,
|
326
|
+
cmd.run(:rails, "server", env: {rails_env: :production})
|
327
327
|
```
|
328
328
|
|
329
329
|
When a value in env is nil, the variable is unset in the child process:
|
330
330
|
|
331
331
|
```ruby
|
332
|
-
cmd.run(:echo,
|
332
|
+
cmd.run(:echo, "hello", env: {foo: "bar", baz: nil})
|
333
333
|
```
|
334
334
|
|
335
335
|
### 3.2 Options
|
@@ -367,27 +367,27 @@ The hash key and value specify a file descriptor in the child process (stderr &
|
|
367
367
|
You can also redirect to a file:
|
368
368
|
|
369
369
|
```ruby
|
370
|
-
cmd.run(:cat, :in =>
|
371
|
-
cmd.run(:cat, :in => open(
|
372
|
-
cmd.run(:ls, :out =>
|
370
|
+
cmd.run(:cat, :in => "file")
|
371
|
+
cmd.run(:cat, :in => open("/etc/passwd"))
|
372
|
+
cmd.run(:ls, :out => "log")
|
373
373
|
cmd.run(:ls, :out => "/dev/null")
|
374
|
-
cmd.run(:ls, :out =>
|
374
|
+
cmd.run(:ls, :out => "out.log", :err => "err.log")
|
375
375
|
cmd.run(:ls, [:out, :err] => "log")
|
376
|
-
cmd.run("ls 1>&2", :err =>
|
376
|
+
cmd.run("ls 1>&2", :err => "log")
|
377
377
|
```
|
378
378
|
|
379
379
|
It is possible to specify flags and permissions of file creation explicitly by passing an array value:
|
380
380
|
|
381
381
|
```ruby
|
382
|
-
cmd.run(:ls, :out => [
|
383
|
-
cmd.run(:ls, :out => [
|
384
|
-
cmd.run(:ls, :out => [
|
382
|
+
cmd.run(:ls, :out => ["log", "w"]) # 0664 assumed
|
383
|
+
cmd.run(:ls, :out => ["log", "w", 0600])
|
384
|
+
cmd.run(:ls, :out => ["log", File::WRONLY|File::EXCL|File::CREAT, 0600])
|
385
385
|
```
|
386
386
|
|
387
387
|
You can, for example, read data from one source and output to another:
|
388
388
|
|
389
389
|
```ruby
|
390
|
-
cmd.run("cat", :in => "Gemfile", :out =>
|
390
|
+
cmd.run("cat", :in => "Gemfile", :out => "gemfile.log")
|
391
391
|
```
|
392
392
|
|
393
393
|
#### 3.2.2 Handling Input
|
@@ -402,7 +402,7 @@ puts "Your name: #{name}"
|
|
402
402
|
In order to execute `cli` with name input do:
|
403
403
|
|
404
404
|
```ruby
|
405
|
-
cmd.run(
|
405
|
+
cmd.run("cli", input: "Piotr\n")
|
406
406
|
# => Your name: Piotr
|
407
407
|
```
|
408
408
|
|
@@ -496,7 +496,7 @@ In addition, when pty device is used, any input to command may be echoed to the
|
|
496
496
|
To change directory in which the command is run pass the `:chdir` option:
|
497
497
|
|
498
498
|
```ruby
|
499
|
-
cmd.run(:echo,
|
499
|
+
cmd.run(:echo, "hello", chdir: "/var/tmp")
|
500
500
|
```
|
501
501
|
|
502
502
|
#### 3.2.8 User
|
@@ -504,7 +504,7 @@ cmd.run(:echo, 'hello', chdir: '/var/tmp')
|
|
504
504
|
To run command as a given user do:
|
505
505
|
|
506
506
|
```ruby
|
507
|
-
cmd.run(:echo,
|
507
|
+
cmd.run(:echo, "hello", user: "piotr")
|
508
508
|
```
|
509
509
|
|
510
510
|
#### 3.2.9 Group
|
@@ -512,7 +512,7 @@ cmd.run(:echo, 'hello', user: 'piotr')
|
|
512
512
|
To run command as part of group do:
|
513
513
|
|
514
514
|
```ruby
|
515
|
-
cmd.run(:echo,
|
515
|
+
cmd.run(:echo, "hello", group: "devs")
|
516
516
|
```
|
517
517
|
|
518
518
|
#### 3.2.10 Umask
|
@@ -520,7 +520,7 @@ cmd.run(:echo, 'hello', group: 'devs')
|
|
520
520
|
To run command with umask do:
|
521
521
|
|
522
522
|
```ruby
|
523
|
-
cmd.run(:echo,
|
523
|
+
cmd.run(:echo, "hello", umask: "007")
|
524
524
|
```
|
525
525
|
|
526
526
|
### 3.3 Result
|
@@ -528,13 +528,13 @@ cmd.run(:echo, 'hello', umask: '007')
|
|
528
528
|
Each time you run command the stdout and stderr are captured and return as result. The result can be examined directly by casting it to tuple:
|
529
529
|
|
530
530
|
```ruby
|
531
|
-
out, err = cmd.run(:echo,
|
531
|
+
out, err = cmd.run(:echo, "Hello")
|
532
532
|
```
|
533
533
|
|
534
534
|
However, if you want to you can defer reading:
|
535
535
|
|
536
536
|
```ruby
|
537
|
-
result = cmd.run(:echo,
|
537
|
+
result = cmd.run(:echo, "Hello")
|
538
538
|
result.out
|
539
539
|
result.err
|
540
540
|
```
|
@@ -544,7 +544,7 @@ result.err
|
|
544
544
|
To check if command exited successfully use `success?`:
|
545
545
|
|
546
546
|
```ruby
|
547
|
-
result = cmd.run(:echo,
|
547
|
+
result = cmd.run(:echo, "Hello")
|
548
548
|
result.success? # => true
|
549
549
|
```
|
550
550
|
|
@@ -553,7 +553,7 @@ result.success? # => true
|
|
553
553
|
To check if command exited unsuccessfully use `failure?` or `failed?`:
|
554
554
|
|
555
555
|
```ruby
|
556
|
-
result = cmd.run(:echo,
|
556
|
+
result = cmd.run(:echo, "Hello")
|
557
557
|
result.failure? # => false
|
558
558
|
result.failed? # => false
|
559
559
|
```
|
@@ -563,7 +563,7 @@ result.failed? # => false
|
|
563
563
|
To check if command ran to completion use `exited?` or `complete?`:
|
564
564
|
|
565
565
|
```ruby
|
566
|
-
result = cmd.run(:echo,
|
566
|
+
result = cmd.run(:echo, "Hello")
|
567
567
|
result.exited? # => true
|
568
568
|
result.complete? # => true
|
569
569
|
```
|
@@ -573,7 +573,7 @@ result.complete? # => true
|
|
573
573
|
The result itself is an enumerable and allows you to iterate over the stdout output:
|
574
574
|
|
575
575
|
```ruby
|
576
|
-
result = cmd.run(:ls,
|
576
|
+
result = cmd.run(:ls, "-1")
|
577
577
|
result.each { |line| puts line }
|
578
578
|
# =>
|
579
579
|
# CHANGELOG.md
|
@@ -596,7 +596,7 @@ TTY::Command.record_separator = "\n\r"
|
|
596
596
|
or configured per `each` call by passing delimiter as an argument:
|
597
597
|
|
598
598
|
```ruby
|
599
|
-
cmd.run(:ls,
|
599
|
+
cmd.run(:ls, "-1").each("\t") { ... }
|
600
600
|
```
|
601
601
|
|
602
602
|
### 3.4 Custom printer
|
data/lib/tty-command.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
require_relative "tty/command"
|
data/lib/tty/command.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
require_relative
|
13
|
-
require_relative
|
3
|
+
require "rbconfig"
|
4
|
+
|
5
|
+
require_relative "command/cmd"
|
6
|
+
require_relative "command/exit_error"
|
7
|
+
require_relative "command/dry_runner"
|
8
|
+
require_relative "command/process_runner"
|
9
|
+
require_relative "command/printers/null"
|
10
|
+
require_relative "command/printers/pretty"
|
11
|
+
require_relative "command/printers/progress"
|
12
|
+
require_relative "command/printers/quiet"
|
13
|
+
require_relative "command/version"
|
14
14
|
|
15
15
|
module TTY
|
16
16
|
class Command
|
@@ -19,9 +19,9 @@ module TTY
|
|
19
19
|
TimeoutExceeded = Class.new(StandardError)
|
20
20
|
|
21
21
|
# Path to the current Ruby
|
22
|
-
RUBY = ENV[
|
23
|
-
RbConfig::CONFIG[
|
24
|
-
RbConfig::CONFIG[
|
22
|
+
RUBY = ENV["RUBY"] || ::File.join(
|
23
|
+
RbConfig::CONFIG["bindir"],
|
24
|
+
RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]
|
25
25
|
)
|
26
26
|
|
27
27
|
WIN_PLATFORMS = /cygwin|mswin|mingw|bccwin|wince|emx/.freeze
|
@@ -35,7 +35,7 @@ module TTY
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def self.windows?
|
38
|
-
!!(RbConfig::CONFIG[
|
38
|
+
!!(RbConfig::CONFIG["host_os"] =~ WIN_PLATFORMS)
|
39
39
|
end
|
40
40
|
|
41
41
|
attr_reader :printer
|
@@ -128,7 +128,7 @@ module TTY
|
|
128
128
|
def wait(*args)
|
129
129
|
pattern = args.pop
|
130
130
|
unless pattern
|
131
|
-
raise ArgumentError,
|
131
|
+
raise ArgumentError, "Please provide condition to wait for"
|
132
132
|
end
|
133
133
|
|
134
134
|
run(*args) do |out, _|
|
@@ -174,7 +174,7 @@ module TTY
|
|
174
174
|
# @api private
|
175
175
|
def command(*args)
|
176
176
|
cmd = Cmd.new(*args)
|
177
|
-
cmd.update(
|
177
|
+
cmd.update(**@cmd_options)
|
178
178
|
cmd
|
179
179
|
end
|
180
180
|
|
@@ -204,7 +204,7 @@ module TTY
|
|
204
204
|
#
|
205
205
|
# @api private
|
206
206
|
def find_printer_class(name)
|
207
|
-
const_name = name.to_s.split(
|
207
|
+
const_name = name.to_s.split("_").map(&:capitalize).join.to_sym
|
208
208
|
if const_name.empty? || !TTY::Command::Printers.const_defined?(const_name)
|
209
209
|
raise ArgumentError, %(Unknown printer type "#{name}")
|
210
210
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "tempfile"
|
4
|
+
require "securerandom"
|
5
|
+
require "io/console"
|
6
6
|
|
7
7
|
module TTY
|
8
8
|
class Command
|
@@ -27,12 +27,12 @@ module TTY
|
|
27
27
|
verbose = cmd.options[:verbose]
|
28
28
|
|
29
29
|
pty = try_loading_pty(verbose) if pty
|
30
|
-
require(
|
30
|
+
require("pty") if pty # load within this scope
|
31
31
|
|
32
32
|
# Create pipes
|
33
|
-
in_rd, in_wr = pty ? PTY.open : IO.pipe(
|
34
|
-
out_rd, out_wr = pty ? PTY.open : IO.pipe(
|
35
|
-
err_rd, err_wr = pty ? PTY.open : IO.pipe(
|
33
|
+
in_rd, in_wr = pty ? PTY.open : IO.pipe("utf-8") # reading
|
34
|
+
out_rd, out_wr = pty ? PTY.open : IO.pipe("utf-8") # writing
|
35
|
+
err_rd, err_wr = pty ? PTY.open : IO.pipe("utf-8") # error
|
36
36
|
in_wr.sync = true
|
37
37
|
|
38
38
|
if binmode
|
@@ -132,7 +132,7 @@ module TTY
|
|
132
132
|
key = fd_to_process_key(spawn_key)
|
133
133
|
value = spawn_value
|
134
134
|
|
135
|
-
if key.to_s ==
|
135
|
+
if key.to_s == "in"
|
136
136
|
value = convert_to_fd(spawn_value)
|
137
137
|
end
|
138
138
|
|
@@ -195,7 +195,7 @@ module TTY
|
|
195
195
|
return object
|
196
196
|
end
|
197
197
|
|
198
|
-
tmp = ::Tempfile.new(::SecureRandom.uuid.split(
|
198
|
+
tmp = ::Tempfile.new(::SecureRandom.uuid.split("-")[0])
|
199
199
|
content = try_reading(object)
|
200
200
|
tmp.write(content)
|
201
201
|
tmp.rewind
|