rexe 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +25 -12
  4. data/exe/rexe +3 -39
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a941b8dc64640ce710ebf30d3f42ed087738b0fa568b57e9009aa0eb4949f36
4
- data.tar.gz: b8f905cd6f2eace78eb3b17a1bb5a3d90b1223416608049f68e014d69ed4ab07
3
+ metadata.gz: 6eb040be974eda6885667fb67e0c90584011309f4150be33c18a1d36f1e6a602
4
+ data.tar.gz: 17a7a2b2447e5836585890d5e3eb698c580d4634e947d5bbc383b81a0072527b
5
5
  SHA512:
6
- metadata.gz: f5d7379fade7a80ac2659d7ea6da584e2f28366552cb94e95f31fc4c692a6ac0524a72838aa80608854ebc1f3619b4a04976c45de409a5f8a2cf9abec9495958
7
- data.tar.gz: '09a15996ad72e8c72c997ee24495727affcc519f09d695dcea6ae73797decf5891681de5820206d77999154b1824911c117cedab617b1ce3c569ce5209329321'
6
+ metadata.gz: e6d582c5bb306c6d613c280729388f3f8eb2dfb4d061f465c6d8b52972ead88d3891a8f78c96f2c5310de9302a959ca1a43b110dcea2cf6967f2f939accab418
7
+ data.tar.gz: d3769eb0bac5176a0118b47679a30a3f6327950377a000ded517b21b3e8d2d3684c390646c15507a0ec731ac51599157b607a0f2f24ce19b20c18a0bd7dff462
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  ## rexe -- Ruby Command Line Executor
2
2
 
3
3
 
4
+ ### v0.7.0
5
+
6
+ * Remove -u option to address issue #1.
7
+
8
+
4
9
  ### v0.6.1
5
10
 
6
11
  * Improve handling of nonexistent load files (-l, -u options).
data/README.md CHANGED
@@ -27,7 +27,7 @@ but it is also a _filter_ in that it can implicitly consume standard input and e
27
27
  As a summary, here is the help text printed out by the application:
28
28
 
29
29
  ```
30
- rexe -- Ruby Command Line Filter/Executor -- v0.6.1 -- https://github.com/keithrbennett/rexe
30
+ rexe -- Ruby Command Line Filter/Executor -- v0.7.0 -- https://github.com/keithrbennett/rexe
31
31
 
32
32
  Executes Ruby code on the command line, optionally taking standard input and writing to standard output.
33
33
 
@@ -35,16 +35,15 @@ Options:
35
35
 
36
36
  -h, --help Print help and exit
37
37
  -l, --load RUBY_FILE(S) Ruby file(s) to load, comma separated, or ! to clear
38
- -u, --load-up RUBY_FILE(S) Ruby file(s) to load, searching up tree, comma separated, or ! to clear
39
38
  -m, --mode MODE Mode with which to handle input (i.e. what `self` will be in the code):
40
39
  -ms for each line to be handled separately as a string
41
40
  -me for an enumerator of lines (least memory consumption for big data)
42
41
  -mb for 1 big string (all lines combined into single multiline string)
43
- -mn to execute the specified Ruby code on no input at all (default)
42
+ -mn to execute the specified Ruby code on no input at all (default)
44
43
  -r, --require REQUIRES Gems and built-in libraries to require, comma separated, or ! to clear
45
44
  -v, --[no-]verbose verbose mode (logs to stderr); to disable, short options: -v n, -v false
46
45
 
47
- If there is an .rexerc file in your home directory, it will be run as Ruby code
46
+ If there is an .rexerc file in your home directory, it will be run as Ruby code
48
47
  before processing the input.
49
48
 
50
49
  If there is a REXE_OPTIONS environment variable, its content will be prepended to the command line
@@ -75,14 +74,6 @@ Other Ruby files can be loaded by `rexe`, to, for example, define classes and me
75
74
 
76
75
  If there is a file named `.rexerc` in the home directory, that will always be loaded without explicitly requesting it on the command line.
77
76
 
78
- #### Searching for Load Files in the Current Directory and Above
79
-
80
- Using the `-u` option, you can specify that the file you want to load should be searched for at the specified directory _and above_. This can be handy when you have project specific configuration and you may be multiple levels below the project root.
81
-
82
- For example, if you run `rexe` from `~/my_project/a/b/c`, and specify `-u load-me.rb`, and `load-me.rb` is located in `~/my_project`, then it will be loaded from there.
83
-
84
- If the file is not found, the failure will be silent and the program will proceed. (Preferred behavior could go either way on this, but the current approach enables you to unconditionally specify a `-u` file in your default `REXE_OPTIONS` environment variable value and have it work regardless of the presence or absence of the file.) If verbose mode is enabled, a message about the failure to find the file will be displayed.
85
-
86
77
  ### Verbose Mode
87
78
 
88
79
  Verbose mode outputs information to standard error (stderr). This information can be redirected, for example to a file named `rexe.log`, by adding `2>& rexe.log` to the command line.
@@ -148,22 +139,28 @@ If you are troubleshooting the setup (i.e. the command line options, loaded file
148
139
  ➜ rexe git:(master) ✗  ls | head -2 | exe/rexe -ms "self + ' --> ' + reverse"
149
140
  CHANGELOG.md --> dm.GOLEGNAHC
150
141
  Gemfile --> elifmeG
142
+ ```
151
143
 
152
144
  ----
153
145
 
146
+ ```
154
147
  # Use input data to create a human friendly message:
155
148
  ➜ ~  uptime | rexe -ms "%Q{System has been up: #{split.first}.}"
156
149
  System has been up: 17:10.
150
+ ```
157
151
 
158
152
  ----
159
153
 
154
+ ```
160
155
  # Create a JSON array of a file listing.
161
156
  # Use the "-me" flag so that all input is treated as a single enumerator of lines.
162
157
  ➜ ~  ls | head -3 | rexe -me -r json "map(&:strip).to_a.to_json"
163
158
  ["AFP.conf","afpovertcp.cfg","afpovertcp.cfg~orig"]
159
+ ```
164
160
 
165
161
  ----
166
162
 
163
+ ```
167
164
  # Create a "pretty" JSON array of a file listing:
168
165
  ➜ ~  ls | head -3 | rexe -me -r json "JSON.pretty_generate(map(&:strip).to_a)"
169
166
  [
@@ -171,18 +168,22 @@ System has been up: 17:10.
171
168
  "afpovertcp.cfg",
172
169
  "afpovertcp.cfg~orig"
173
170
  ]
171
+ ```
174
172
 
175
173
  ----
176
174
 
175
+ ```
177
176
  # Create a YAML array of a file listing:
178
177
  ➜ ~  ls | head -3 | rexe -me -r yaml "map(&:strip).to_a.to_yaml"
179
178
  ---
180
179
  - AFP.conf
181
180
  - afpovertcp.cfg
182
181
  - afpovertcp.cfg~orig
182
+ ```
183
183
 
184
184
  ----
185
185
 
186
+ ```
186
187
  # Use AwesomePrint to print a file listing.
187
188
  # (Rather than calling the `ap` method on the object to print,
188
189
  # call the `ai` method _on_ the object to print:
@@ -192,17 +193,21 @@ System has been up: 17:10.
192
193
  [1] "afpovertcp.cfg",
193
194
  [2] "afpovertcp.cfg~orig"
194
195
  ]
196
+ ```
195
197
 
196
198
  ----
197
199
 
200
+ ```
198
201
  # Don't use input at all, so use "-mn" to tell rexe not to expect input.
199
202
  # -mn is the default, so it works with or without specifying that option:
200
203
  ➜ ~  rexe "puts %Q{The time is now #{Time.now}}"
201
204
  ➜ ~  rexe -mn "puts %Q{The time is now #{Time.now}}"
202
205
  The time is now 2019-02-04 17:20:03 +0700
206
+ ```
203
207
 
204
208
  ----
205
209
 
210
+ ```
206
211
  # Use REXE_OPTIONS environment variable to eliminate the need to specify
207
212
  # options on each invocation:
208
213
 
@@ -221,11 +226,13 @@ Traceback (most recent call last):
221
226
  # Now that command that previously failed will succeed:
222
227
  ➜ ~  rexe "[JSON, YAML, AwesomePrint].to_s"
223
228
  [JSON, Psych, AwesomePrint]
229
+ ```
224
230
 
225
231
  ----
226
232
 
227
233
  Access public JSON data and print it with awesome_print, using the ruby interpreter directly:
228
234
 
235
+ ```
229
236
  ➜ ~  export JSON_TEXT=`curl https://api.exchangeratesapi.io/latest`
230
237
  ➜ ~  echo $JSON_TEXT | ruby -r json -r awesome_print -e 'ap JSON.parse(STDIN.read)'
231
238
 
@@ -238,11 +245,14 @@ Access public JSON data and print it with awesome_print, using the ruby interpre
238
245
  "MXN" => 21.7301,
239
246
  ...
240
247
  }
248
+ ```
241
249
 
242
250
 
243
251
  This `rexe` command will have the same effect:
244
252
 
253
+ ```
245
254
  ➜ ~  echo $JSON_TEXT | rexe -mb -r awesome_print,json "JSON.parse(self).ai"
255
+ ```
246
256
 
247
257
  The input modes that directly support standard input will send the last evaluated value to standard output.
248
258
  So instead of calling AwesomePrint's `ap`, we call `ai` (awesome inspect) on the object we want to display.
@@ -250,13 +260,16 @@ So instead of calling AwesomePrint's `ap`, we call `ai` (awesome inspect) on the
250
260
  In "no input" mode, there's nothing preventing us from handling the input ourselves (e.g. as `STDIN.read`,
251
261
  so we could have accomplished the same thing like this:
252
262
 
263
+ ```
253
264
  echo $JSON_TEXT | rexe -r awesome_print,json "ap JSON.parse(STDIN.read)"
265
+ ```
254
266
 
255
267
  ----
256
268
 
257
269
  Often we want to treat input as an array. Assuming there won't be too much to fit in memory,
258
270
  we can instruct `rexe` to treat input as an `Enumerable` (using the `-me` option), and then
259
271
  calling `to_a` on it. The following code prints the environment variables, sorted, with Awesome Print:
272
+ ```
260
273
  ➜ ~  env | rexe -me -r awesome_print sort.to_a.ai
261
274
  [
262
275
  ...
data/exe/rexe CHANGED
@@ -9,7 +9,7 @@ require 'shellwords'
9
9
 
10
10
  class Rexe < Struct.new(:input_mode, :loads, :requires, :verbose)
11
11
 
12
- VERSION = '0.6.1'
12
+ VERSION = '0.7.0'
13
13
 
14
14
  def initialize
15
15
  self.input_mode = :no_input
@@ -30,7 +30,6 @@ class Rexe < Struct.new(:input_mode, :loads, :requires, :verbose)
30
30
 
31
31
  -h, --help Print help and exit
32
32
  -l, --load RUBY_FILE(S) Ruby file(s) to load, comma separated, or ! to clear
33
- -u, --load-up RUBY_FILE(S) Ruby file(s) to load, searching up tree, comma separated, or ! to clear
34
33
  -m, --mode MODE Mode with which to handle input (i.e. what `self` will be in the code):
35
34
  -ms for each line to be handled separately as a string
36
35
  -me for an enumerator of lines (least memory consumption for big data)
@@ -82,22 +81,6 @@ class Rexe < Struct.new(:input_mode, :loads, :requires, :verbose)
82
81
  end
83
82
  end
84
83
 
85
- parser.on('-u', '--load_up RUBY_FILE(S)', 'Ruby file(s) to load, searching up tree, comma separated, or ! to clear') do |v|
86
- if v == '!'
87
- self.loads.clear
88
- else
89
- filespecs = v.split(',').map(&:strip)
90
- filespecs.each do |filespec|
91
- found_file = find_file_up_tree(filespec)
92
- if found_file
93
- self.loads << found_file
94
- else
95
- log_if_verbose("\nDid not find load file '#{filespec}' in this directory or higher.\n\n")
96
- end
97
- end
98
- end
99
- end
100
-
101
84
  parser.on('-m', '--mode MODE',
102
85
  'Mode with which to handle input (-ms (default), -me, -mb, mn)') do |v|
103
86
 
@@ -141,21 +124,6 @@ class Rexe < Struct.new(:input_mode, :loads, :requires, :verbose)
141
124
  end
142
125
 
143
126
 
144
- # Looks in this directory and all above it for the filename
145
- # @return the first match found, or nil if none
146
- def find_file_up_tree(filespec)
147
- filespec = File.expand_path(filespec)
148
- basename = File.basename(filespec)
149
-
150
- loop do
151
- return filespec if File.exist?(filespec)
152
- return nil if File.dirname(filespec) == File::SEPARATOR
153
- new_dir = File.expand_path(File.join(File.dirname(filespec), '..'))
154
- filespec = File.join(new_dir, basename)
155
- end
156
- end
157
-
158
-
159
127
  def load_global_config_if_exists
160
128
  filespec = File.join(Dir.home, '.rexerc')
161
129
  exists = File.exists?(filespec)
@@ -192,15 +160,11 @@ class Rexe < Struct.new(:input_mode, :loads, :requires, :verbose)
192
160
  log_if_verbose('Source Code: ' + ARGV.join(' '))
193
161
  log_if_verbose('Options: ' + self.to_h.to_s)
194
162
 
195
- requires.each do |r|
196
- require(r)
197
- end
163
+ requires.each { |r| require(r) }
198
164
 
199
165
  load_global_config_if_exists
200
166
 
201
- loads.each do |file|
202
- load(file)
203
- end
167
+ loads.each { |file| load(file) }
204
168
 
205
169
  source_code = "Proc.new { #{ARGV.join(' ')} }"
206
170
  code = eval(source_code)
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.6.1
4
+ version: 0.7.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-24 00:00:00.000000000 Z
11
+ date: 2019-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler