rexe 0.5.0 → 0.6.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/README.md +66 -28
- data/exe/rexe +5 -5
- data/rexe.gemspec +2 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b24d04f1de2c1db6d70d9d49f01f1ad5ff1451322e708a81a1126cebaa4857ae
|
4
|
+
data.tar.gz: 6a4012b73000d9cde679ca2a83fccd3be39dcdbbe528aba59aaccdb6e81161bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac45230cca67ffb89b7fef9135e7e8b3f33347c525e8f9cd71ff99c066d736476bf914826fe9e9374e7048f676d92d47cbbb76f247cbb573c525b871117fb845
|
7
|
+
data.tar.gz: 24dca459efcb4e68c1553ebec376ef89c050dda5de353458a46d920012a86ea27f4bde2ea146eda4b9bede9d6dc669f8916ca058abc62efae3f9fbcea7c1fa2f
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Rexe
|
2
2
|
|
3
|
-
A configurable Ruby command line filter
|
3
|
+
A configurable Ruby command line executor and filter.
|
4
4
|
|
5
5
|
|
6
6
|
|
@@ -26,7 +26,7 @@ rexe is a _filter_ in that it can consume standard input and emit standard outpu
|
|
26
26
|
As a summary, here is the help text printed out by the application:
|
27
27
|
|
28
28
|
```
|
29
|
-
rexe -- Ruby Command Line Filter/Executor -- v0.
|
29
|
+
rexe -- Ruby Command Line Filter/Executor -- v0.6.0 -- https://github.com/keithrbennett/rexe
|
30
30
|
|
31
31
|
Executes Ruby code on the command line, optionally taking standard input and writing to standard output.
|
32
32
|
|
@@ -36,10 +36,10 @@ Options:
|
|
36
36
|
-l, --load RUBY_FILE(S) Ruby file(s) to load, comma separated, or ! to clear
|
37
37
|
-u, --load-up RUBY_FILE(S) Ruby file(s) to load, searching up tree, comma separated, or ! to clear
|
38
38
|
-m, --mode MODE Mode with which to handle input (i.e. what `self` will be in the code):
|
39
|
-
-ms for each line to be handled separately as a string
|
39
|
+
-ms for each line to be handled separately as a string
|
40
40
|
-me for an enumerator of lines (least memory consumption for big data)
|
41
41
|
-mb for 1 big string (all lines combined into single multiline string)
|
42
|
-
-mn to execute the specified Ruby code on no input at all
|
42
|
+
-mn to execute the specified Ruby code on no input at all (default)
|
43
43
|
-r, --require REQUIRES Gems and built-in libraries to require, comma separated, or ! to clear
|
44
44
|
-v, --[no-]verbose Verbose mode (logs to stderr) Verbose off short options: -v n, -v false
|
45
45
|
|
@@ -52,7 +52,10 @@ so that you can specify options implicitly (e.g. `export REXE_OPTIONS="-r awesom
|
|
52
52
|
|
53
53
|
### Input Mode
|
54
54
|
|
55
|
-
When it is used as a filter, the input is accessed differently in the source code
|
55
|
+
When it is used as a filter, the input is accessed differently in the source code
|
56
|
+
depending on the mode that was specified (see example section below for examples).
|
57
|
+
The mode letter is appended to `-m` on the command line;
|
58
|
+
`n` (_no input_) mode is the default.
|
56
59
|
|
57
60
|
* `s` - _string_ mode - the source code is run once on each line of input, and `self` is each line of text
|
58
61
|
* `e` - _enumerator_ mode - the code is run once on the enumerator of all lines; `self` is the enumerator, so you can call `map`, `to_a`, `select`, etc without explicitly specifying `self`.
|
@@ -139,29 +142,29 @@ If you are troubleshooting the setup (i.e. the command line options, loaded file
|
|
139
142
|
|
140
143
|
```
|
141
144
|
# Call reverse on listed file.
|
142
|
-
#
|
145
|
+
# Need to specify the mode, since it defaults to "n" ("-mn"),
|
143
146
|
# which treats every line separately.
|
144
|
-
➜ rexe git:(master) ✗ ls | head -2 | exe/rexe "self + ' --> ' + reverse"
|
147
|
+
➜ rexe git:(master) ✗ ls | head -2 | exe/rexe -ms "self + ' --> ' + reverse"
|
145
148
|
CHANGELOG.md --> dm.GOLEGNAHC
|
146
149
|
Gemfile --> elifmeG
|
147
150
|
|
148
151
|
----
|
149
152
|
|
150
153
|
# Use input data to create a human friendly message:
|
151
|
-
➜ ~ uptime | rexe "%Q{System has been up: #{split.first}.}"
|
154
|
+
➜ ~ uptime | rexe -ms "%Q{System has been up: #{split.first}.}"
|
152
155
|
System has been up: 17:10.
|
153
156
|
|
154
157
|
----
|
155
158
|
|
156
159
|
# Create a JSON array of a file listing.
|
157
160
|
# Use the "-me" flag so that all input is treated as a single enumerator of lines.
|
158
|
-
➜
|
161
|
+
➜ ~ ls | head -3 | rexe -me -r json "map(&:strip).to_a.to_json"
|
159
162
|
["AFP.conf","afpovertcp.cfg","afpovertcp.cfg~orig"]
|
160
163
|
|
161
164
|
----
|
162
165
|
|
163
166
|
# Create a "pretty" JSON array of a file listing:
|
164
|
-
➜
|
167
|
+
➜ ~ ls | head -3 | rexe -me -r json "JSON.pretty_generate(map(&:strip).to_a)"
|
165
168
|
[
|
166
169
|
"AFP.conf",
|
167
170
|
"afpovertcp.cfg",
|
@@ -171,7 +174,7 @@ System has been up: 17:10.
|
|
171
174
|
----
|
172
175
|
|
173
176
|
# Create a YAML array of a file listing:
|
174
|
-
➜
|
177
|
+
➜ ~ ls | head -3 | rexe -me -r yaml "map(&:strip).to_a.to_yaml"
|
175
178
|
---
|
176
179
|
- AFP.conf
|
177
180
|
- afpovertcp.cfg
|
@@ -182,7 +185,7 @@ System has been up: 17:10.
|
|
182
185
|
# Use AwesomePrint to print a file listing.
|
183
186
|
# (Rather than calling the `ap` method on the object to print,
|
184
187
|
# call the `ai` method _on_ the object to print:
|
185
|
-
➜
|
188
|
+
➜ ~ ls | head -3 | rexe -me -r awesome_print "map(&:chomp).ai"
|
186
189
|
[
|
187
190
|
[0] "AFP.conf",
|
188
191
|
[1] "afpovertcp.cfg",
|
@@ -192,7 +195,9 @@ System has been up: 17:10.
|
|
192
195
|
----
|
193
196
|
|
194
197
|
# Don't use input at all, so use "-mn" to tell rexe not to expect input.
|
195
|
-
|
198
|
+
# -mn is the default, so it works with or without specifying that option:
|
199
|
+
➜ ~ rexe "puts %Q{The time is now #{Time.now}}"
|
200
|
+
➜ ~ rexe -mn "puts %Q{The time is now #{Time.now}}"
|
196
201
|
The time is now 2019-02-04 17:20:03 +0700
|
197
202
|
|
198
203
|
----
|
@@ -200,8 +205,9 @@ The time is now 2019-02-04 17:20:03 +0700
|
|
200
205
|
# Use REXE_OPTIONS environment variable to eliminate the need to specify
|
201
206
|
# options on each invocation:
|
202
207
|
|
203
|
-
# First it will fail since these symbols have not been loaded via require
|
204
|
-
|
208
|
+
# First it will fail since these symbols have not been loaded via require
|
209
|
+
(unless these requires have been specified elsewhere in the configuration):
|
210
|
+
➜ ~ rexe "[JSON, YAML, AwesomePrint]"
|
205
211
|
Traceback (most recent call last):
|
206
212
|
...
|
207
213
|
(eval):1:in `block in call': uninitialized constant Rexe::JSON (NameError)
|
@@ -209,29 +215,48 @@ Traceback (most recent call last):
|
|
209
215
|
# Now we specify the requires in the REXE_OPTIONS environment variable.
|
210
216
|
# Contents of this variable will be prepended to the arguments
|
211
217
|
# specified on the command line.
|
212
|
-
➜
|
218
|
+
➜ ~ export REXE_OPTIONS="-r json,yaml,awesome_print"
|
213
219
|
|
214
220
|
# Now that command that previously failed will succeed:
|
215
|
-
➜
|
221
|
+
➜ ~ rexe "[JSON, YAML, AwesomePrint].to_s"
|
216
222
|
[JSON, Psych, AwesomePrint]
|
217
223
|
|
218
224
|
----
|
219
225
|
|
220
|
-
Access public JSON data and print it with awesome_print:
|
226
|
+
Access public JSON data and print it with awesome_print, using the ruby interpreter directly:
|
221
227
|
|
222
|
-
➜
|
223
|
-
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
228
|
+
➜ ~ export JSON_TEXT=`curl https://api.exchangeratesapi.io/latest`
|
229
|
+
➜ ~ echo $JSON_TEXT | ruby -r json -r awesome_print -e 'ap JSON.parse(STDIN.read)'
|
230
|
+
|
231
|
+
{
|
232
|
+
"base" => "EUR",
|
233
|
+
"date" => "2019-02-20",
|
234
|
+
"rates" => {
|
235
|
+
"NZD" => 1.6513,
|
236
|
+
"CAD" => 1.4956,
|
237
|
+
"MXN" => 21.7301,
|
238
|
+
...
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
This `rexe` command will have the same effect:
|
243
|
+
|
244
|
+
➜ ~ echo $JSON_TEXT | rexe -mb -r awesome_print,json "JSON.parse(self).ai"
|
245
|
+
|
246
|
+
The input modes that directly support standard input will send the last evaluated value to standard output.
|
247
|
+
So instead of calling AwesomePrint's `ap`, we call `ai` (awesome inspect) on the object we want to display.
|
248
|
+
|
249
|
+
In "no input" mode, there's nothing preventing us from handling the input ourselves (e.g. as `STDIN.read`,
|
250
|
+
so we could have accomplished the same thing like this:
|
251
|
+
|
252
|
+
echo $JSON_TEXT | rexe -r awesome_print,json "ap JSON.parse(STDIN.read)"
|
230
253
|
|
231
254
|
----
|
232
255
|
|
233
|
-
|
234
|
-
|
256
|
+
Often we want to treat input as an array. Assuming there won't be too much to fit in memory,
|
257
|
+
we can instruct `rexe` to treat input as an `Enumerable` (using the `-me` option), and then
|
258
|
+
calling `to_a` on it. The following code prints the environment variables, sorted, with Awesome Print:
|
259
|
+
➜ ~ env | rexe -me -r awesome_print sort.to_a.ai
|
235
260
|
[
|
236
261
|
...
|
237
262
|
[ 4] "COLORFGBG=15;0\n",
|
@@ -239,6 +264,19 @@ Access public JSON data and print it with awesome_print:
|
|
239
264
|
...
|
240
265
|
```
|
241
266
|
|
267
|
+
----
|
268
|
+
|
269
|
+
Here are two ways to print the number of entries in a directory.
|
270
|
+
Notice that the two number differ by 1.
|
271
|
+
|
272
|
+
```
|
273
|
+
➜ ~ rexe -mn "puts %Q{This directory has #{Dir['*'].size} entries.}"
|
274
|
+
This directory has 210 entries.
|
275
|
+
➜ ~ echo `ls -l | wc -l` | rexe -ms "%Q{This directory has #{self} entries.}"
|
276
|
+
This directory has 211 entries.
|
277
|
+
```
|
278
|
+
|
279
|
+
|
242
280
|
## License
|
243
281
|
|
244
282
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/exe/rexe
CHANGED
@@ -9,10 +9,10 @@ require 'shellwords'
|
|
9
9
|
|
10
10
|
class Rexe < Struct.new(:input_mode, :loads, :requires, :verbose)
|
11
11
|
|
12
|
-
VERSION = '0.
|
12
|
+
VERSION = '0.6.0'
|
13
13
|
|
14
14
|
def initialize
|
15
|
-
self.input_mode = :
|
15
|
+
self.input_mode = :no_input
|
16
16
|
self.loads = []
|
17
17
|
self.requires = []
|
18
18
|
self.verbose = false
|
@@ -32,17 +32,17 @@ class Rexe < Struct.new(:input_mode, :loads, :requires, :verbose)
|
|
32
32
|
-l, --load RUBY_FILE(S) Ruby file(s) to load, comma separated, or ! to clear
|
33
33
|
-u, --load-up RUBY_FILE(S) Ruby file(s) to load, searching up tree, comma separated, or ! to clear
|
34
34
|
-m, --mode MODE Mode with which to handle input (i.e. what `self` will be in the code):
|
35
|
-
-ms for each line to be handled separately as a string
|
35
|
+
-ms for each line to be handled separately as a string
|
36
36
|
-me for an enumerator of lines (least memory consumption for big data)
|
37
37
|
-mb for 1 big string (all lines combined into single multiline string)
|
38
|
-
-mn to execute the specified Ruby code on no input at all
|
38
|
+
-mn to execute the specified Ruby code on no input at all (default)
|
39
39
|
-r, --require REQUIRES Gems and built-in libraries to require, comma separated, or ! to clear
|
40
40
|
-v, --[no-]verbose Verbose mode (logs to stderr) Verbose off short options: -v n, -v false
|
41
41
|
|
42
42
|
If there is an .rexerc file in your home directory, it will be run as Ruby code
|
43
43
|
before processing the input.
|
44
44
|
|
45
|
-
If there is
|
45
|
+
If there is a REXE_OPTIONS environment variable, its content will be prepended to the command line
|
46
46
|
so that you can specify options implicitly (e.g. `export REXE_OPTIONS="-r awesome_print,yaml"`)
|
47
47
|
|
48
48
|
HEREDOC
|
data/rexe.gemspec
CHANGED
@@ -42,4 +42,6 @@ Gem::Specification.new do |spec|
|
|
42
42
|
spec.add_development_dependency "os"
|
43
43
|
spec.add_development_dependency "rake", "~> 12.3"
|
44
44
|
spec.add_development_dependency "rspec", "~> 3.0"
|
45
|
+
|
46
|
+
spec.post_install_message = "\n\nWARNING! The default input mode was changed from -ms to -mn in version 0.6.0.\n\n"
|
45
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rexe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Bennett
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,7 +94,11 @@ metadata:
|
|
94
94
|
homepage_uri: https://github.com/keithrbennett/rexe
|
95
95
|
source_code_uri: https://github.com/keithrbennett/rexe
|
96
96
|
changelog_uri: https://github.com/keithrbennett/rexe/blob/master/README.md
|
97
|
-
post_install_message:
|
97
|
+
post_install_message: |2+
|
98
|
+
|
99
|
+
|
100
|
+
WARNING! The default input mode was changed from -ms to -mn in version 0.6.0.
|
101
|
+
|
98
102
|
rdoc_options: []
|
99
103
|
require_paths:
|
100
104
|
- lib
|