tty-command 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fc9ae4bb4984bdcf9fdc7a49fd6b9b912ff60a2
4
- data.tar.gz: d47f52018f538b780aac9eba1abafcf696d1ebd7
3
+ metadata.gz: 6c367c70f87e798b8c57dd55bd3b3d1c7b57af06
4
+ data.tar.gz: f68e94e54364a591eb73b639cd3c7aca74135372
5
5
  SHA512:
6
- metadata.gz: 6b4b96a1351485b1b4fa436a58adc71d08f91f21e81f2f4cdeea78b10773bce7d5681e6340add08d963a57e17183b65799c17fc2d74ec32c48c5b325950994e6
7
- data.tar.gz: ba6f5e69a2588cdf37f33bea99e10147ccc0b0d0b5f3f91dd6d0b24ec44cac7b24627184644ac07627557d91de950f42012c6cfdebab5eea644f900a72e8d598
6
+ metadata.gz: 7087e65b1f788c61fcfebd95f243595494d9ce75a7d3f8dc2a6782038bad9d412bf80df335017ecddbfa8248da1ea22250b0cc7e714390a54d1518c9e19d1490
7
+ data.tar.gz: b50d50c712cdd7b117bb138e88e29035b20b9ddd6d668b01ee39f6fc34443aaf2c0dab5e331ed6f33dcba4ff727866139d911206f9af09b5fbe74c911266121d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.2.0] - 2016-07-03
4
+
5
+ ### Added
6
+ * Add ruby interperter helper
7
+
8
+ ### Fixed
9
+ * Fix multibyte content truncation for streams by Ondrej Moravcik(@ondra-m)
10
+
3
11
  ## [v0.1.0] - 2016-05-29
4
12
 
5
13
  * Initial implementation and release
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 run to complition use `exited?` or `complete?`:
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]
@@ -136,7 +136,8 @@ module TTY
136
136
  end
137
137
  end
138
138
 
139
- # Enclose s in quotes if it contains characters that require escaping
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[over..-1]
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[0...n], dest[n..-1]
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[n..-1]
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[0...offset]
103
- value = value[offset..-1]
102
+ dst << value.byteslice(0...offset)
103
+ value = value.byteslice(offset..-1)
104
104
  end
105
105
  value
106
106
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  class Command
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end # Command
7
7
  end # TTY
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.1.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-05-29 00:00:00.000000000 Z
11
+ date: 2016-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel