tty-command 0.1.0 → 0.2.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/CHANGELOG.md +8 -0
- data/README.md +10 -1
- data/lib/tty/command.rb +21 -0
- data/lib/tty/command/cmd.rb +2 -1
- data/lib/tty/command/truncator.rb +5 -5
- data/lib/tty/command/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c367c70f87e798b8c57dd55bd3b3d1c7b57af06
|
4
|
+
data.tar.gz: f68e94e54364a591eb73b639cd3c7aca74135372
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7087e65b1f788c61fcfebd95f243595494d9ce75a7d3f8dc2a6782038bad9d412bf80df335017ecddbfa8248da1ea22250b0cc7e714390a54d1518c9e19d1490
|
7
|
+
data.tar.gz: b50d50c712cdd7b117bb138e88e29035b20b9ddd6d668b01ee39f6fc34443aaf2c0dab5e331ed6f33dcba4ff727866139d911206f9af09b5fbe74c911266121d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -49,6 +49,7 @@ Or install it yourself as:
|
|
49
49
|
* [2.3. Test](#23-test)
|
50
50
|
* [2.4. Logging](#24-logging)
|
51
51
|
* [2.5. Dry run](#25-dry-run)
|
52
|
+
* [2.6. Ruby interpreter](#26-ruby-interpreter)
|
52
53
|
* [3. Advanced Interface](#3-advanced-interface)
|
53
54
|
* [3.1. Environment variables](#31-environment-variables)
|
54
55
|
* [3.2. Options](#32-options)
|
@@ -194,6 +195,14 @@ To check what mode the command is in use the `dry_run?` query helper:
|
|
194
195
|
cmd.dry_run? # => true
|
195
196
|
```
|
196
197
|
|
198
|
+
### 2.6 Ruby interpreter
|
199
|
+
|
200
|
+
In order to run a command with Ruby interpreter do:
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
cmd.ruby %q{-e "puts 'Hello world'"}
|
204
|
+
```
|
205
|
+
|
197
206
|
## 3. Advanced Interface
|
198
207
|
|
199
208
|
### 3.1 Environment variables
|
@@ -326,7 +335,7 @@ result.failed? # => false
|
|
326
335
|
|
327
336
|
#### 3.3.3 exited?
|
328
337
|
|
329
|
-
To check if command
|
338
|
+
To check if command ran to completion use `exited?` or `complete?`:
|
330
339
|
|
331
340
|
```ruby
|
332
341
|
result = cmd.run(:echo, 'Hello')
|
data/lib/tty/command.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'thread'
|
4
|
+
require 'rbconfig'
|
4
5
|
require 'tty/command/version'
|
5
6
|
require 'tty/command/cmd'
|
6
7
|
require 'tty/command/exit_error'
|
@@ -17,6 +18,11 @@ module TTY
|
|
17
18
|
|
18
19
|
TimeoutExceeded = Class.new(StandardError)
|
19
20
|
|
21
|
+
# Path to the current Ruby
|
22
|
+
RUBY = ENV['RUBY'] || File.join(
|
23
|
+
RbConfig::CONFIG['bindir'],
|
24
|
+
RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT'])
|
25
|
+
|
20
26
|
attr_reader :printer
|
21
27
|
|
22
28
|
# Initialize a Command object
|
@@ -94,6 +100,21 @@ module TTY
|
|
94
100
|
run!(:test, *args).success?
|
95
101
|
end
|
96
102
|
|
103
|
+
# Run Ruby interperter with the given arguments
|
104
|
+
#
|
105
|
+
# @example
|
106
|
+
# ruby %q{-e "puts 'Hello world'"}
|
107
|
+
#
|
108
|
+
# @api public
|
109
|
+
def ruby(*args, &block)
|
110
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
111
|
+
if args.length > 1
|
112
|
+
run(*([RUBY] + args + [options]), &block)
|
113
|
+
else
|
114
|
+
run("#{RUBY} #{args.first}", options, &block)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
97
118
|
# Check if in dry mode
|
98
119
|
#
|
99
120
|
# @return [Boolean]
|
data/lib/tty/command/cmd.rb
CHANGED
@@ -136,7 +136,8 @@ module TTY
|
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
-
# Enclose
|
139
|
+
# Enclose argument in quotes if it contains
|
140
|
+
# characters that require escaping
|
140
141
|
#
|
141
142
|
# @param [String] arg
|
142
143
|
# the argument to escape
|
@@ -36,7 +36,7 @@ module TTY
|
|
36
36
|
content = append(content, @prefix)
|
37
37
|
|
38
38
|
if (over = (content.bytesize - @max_size)) > 0
|
39
|
-
content = content
|
39
|
+
content = content.byteslice(over..-1)
|
40
40
|
@skipped += over
|
41
41
|
end
|
42
42
|
|
@@ -81,10 +81,10 @@ module TTY
|
|
81
81
|
bytes = value.bytesize
|
82
82
|
n = bytes < dest.bytesize ? bytes : dest.bytesize
|
83
83
|
|
84
|
-
head, tail = dest
|
84
|
+
head, tail = dest.byteslice(0...n), dest.byteslice(n..-1)
|
85
85
|
dest.replace("#{tail}#{value[0...n]}")
|
86
86
|
@skipped += head.bytesize
|
87
|
-
value
|
87
|
+
value.byteslice(n..-1)
|
88
88
|
end
|
89
89
|
|
90
90
|
# Append value to destination
|
@@ -99,8 +99,8 @@ module TTY
|
|
99
99
|
if remain > 0
|
100
100
|
value_bytes = value.to_s.bytesize
|
101
101
|
offset = value_bytes < remain ? value_bytes : remain
|
102
|
-
dst << value
|
103
|
-
value = value
|
102
|
+
dst << value.byteslice(0...offset)
|
103
|
+
value = value.byteslice(offset..-1)
|
104
104
|
end
|
105
105
|
value
|
106
106
|
end
|
data/lib/tty/command/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|