rexe 1.0.3 → 1.3.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 +19 -0
  3. data/README.md +9 -4
  4. data/exe/rexe +94 -76
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76e23653efa666a3b5ebf1b991614dd9b98bed082d54cda2f660e1991a62d7d8
4
- data.tar.gz: d01960aa820c05b2a933f0cee0fa78f894afd43ae275da31b5efad96ae5ee89e
3
+ metadata.gz: 8ab00704245578c9561f0505ecf8bd7e89726a1c8c6df3ffd6a7ac42cd47cde9
4
+ data.tar.gz: f9a016b6c972c9960f6e42042ad5531b095fb69ccee8409b770d3da52c40f3d6
5
5
  SHA512:
6
- metadata.gz: b5c57cc8ff200ae90c8d6d143b444f0c0b58ad91a93dc7027be280b5c0396b01da2a67f67f475db7108924b117f53e0d6f7ac3583502846a8c5941edeba6693f
7
- data.tar.gz: 1e6227b7c651668a7ca306c3bb70fba18a80fd8c6018a3db9fdca2185b94f988fcf289898fa432b33af118261a6dcb9ca426c5cdb29ab31e2bb878929785edbd
6
+ metadata.gz: 34399b21ef6425c9107f42fe5809c4d3e4b98e5a1e88680dfdfb074f0b8c5b3f5e94c2b83d31299a948d2b54b873e41580d0cb1d4f1c57de2f10a29bce3a4da6
7
+ data.tar.gz: 7956d7b7b7f0ee154f345c9fd375e86913d9abf8b38f0e2d0d69cd5b2354ec6db9675bb3b425f077f0b4b1f572970c177daa64ce299a3293cd86dd45da219eee
@@ -1,5 +1,24 @@
1
1
  ## rexe -- Ruby Command Line Executor/Filter
2
2
 
3
+ ### 1.3.0
4
+
5
+ * Document --project-url option.
6
+ * Add undocumented option --open-project to output Github project URL.
7
+ * Simplify test as per @davetron5000's array based approach.
8
+ * Fix context do/end in test code.
9
+ * Froze strings: VERSION, PROJECT_URL, help_text.
10
+
11
+
12
+ ### 1.2.0
13
+
14
+ * Add --project-url option to output project URL on Github, then exit
15
+
16
+
17
+ ### 1.1.0
18
+
19
+ * Enable specifying different output formats for tty and block devices. (#4)
20
+ * Outputs exception text on error instead of just exception class.
21
+
3
22
 
4
23
  ### 1.0.3
5
24
 
data/README.md CHANGED
@@ -73,7 +73,7 @@ Rexe is at https://github.com/keithrbennett/rexe and can be installed with `gem
73
73
  Here is rexe's help text as of the time of this writing:
74
74
 
75
75
  ```
76
- rexe -- Ruby Command Line Executor/Filter -- v1.0.3 -- https://github.com/keithrbennett/rexe
76
+ rexe -- Ruby Command Line Executor/Filter -- v1.3.0 -- https://github.com/keithrbennett/rexe
77
77
 
78
78
  Executes Ruby code on the command line,
79
79
  optionally automating management of standard input and standard output,
@@ -115,6 +115,8 @@ Options:
115
115
  -op Puts
116
116
  -os to_s
117
117
  -oy YAML
118
+ If 2 letters are provided, 1st is for tty devices, 2nd for block
119
+ --project-url Outputs project URL on Github, then exits
118
120
  -r, --require REQUIRE(S) Gems and built-in libraries to require, comma separated;
119
121
  ! to clear all, or precede a name with '-' to remove
120
122
  -v, --version Prints version and exits
@@ -263,12 +265,13 @@ If you would like to append this informational output to a file(e.g. `rexe.log`)
263
265
  Rexe tries to make it simple and convenient for you to handle standard input, and in different ways. Here is the help text relating to input modes:
264
266
 
265
267
  ```
266
- -m, --input_mode MODE Input preprocessing mode (determines what `self` will be):
268
+ -m, --input_mode MODE Input preprocessing mode (determines what `self` will be)
269
+ defaults to -mn (none)
267
270
  -ml line; each line is ingested as a separate string
268
271
  -me enumerator (each_line on STDIN or File)
269
272
  -mb big string; all lines combined into one string
270
- -mn none (default); no input preprocessing;
271
- self is an Object.new
273
+ -mn none (default); no input preprocessing;
274
+ self is an Object.new
272
275
  ```
273
276
 
274
277
  The first three are _filter_ modes; they make standard input available to your code as `self`.
@@ -369,6 +372,8 @@ All formats will implicitly `require` anything needed to accomplish their task (
369
372
 
370
373
  The default is `-on` to produce no output at all (unless explicitly coded to do so). If you prefer a different default such as `-op` for _puts_ mode, you can specify that in your `REXE_OPTIONS` environment variable.
371
374
 
375
+ If two letters are provided, the first will be used for tty devices (e.g. the terminal when not redirected or piped), and the second for block devices (e.g. when redirected or piped to another process).
376
+
372
377
  You may wonder why these formats are provided, given that their functionality could be included in the custom code instead. Here's why:
373
378
 
374
379
  * The savings in command line length goes a long way to making these commands more readable and feasible.
data/exe/rexe CHANGED
@@ -12,9 +12,9 @@ require 'shellwords'
12
12
 
13
13
  class Rexe
14
14
 
15
- VERSION = '1.0.3'
15
+ VERSION = '1.3.0'.freeze
16
16
 
17
- PROJECT_URL = 'https://github.com/keithrbennett/rexe'
17
+ PROJECT_URL = 'https://github.com/keithrbennett/rexe'.freeze
18
18
 
19
19
 
20
20
  module Helpers
@@ -25,7 +25,7 @@ class Rexe
25
25
  yield
26
26
  rescue Exception => e
27
27
  unless e.class == SystemExit
28
- $stderr.puts('rexe: ' << e.class.to_s)
28
+ $stderr.puts('rexe: ' << e.to_s)
29
29
  $stderr.puts("Use the -h option to get help.")
30
30
  exit(-1)
31
31
  end
@@ -40,6 +40,8 @@ class Rexe
40
40
  :input_mode,
41
41
  :loads,
42
42
  :output_format,
43
+ :output_format_tty,
44
+ :output_format_block,
43
45
  :requires,
44
46
  :log_format,
45
47
  :noop)
@@ -53,13 +55,15 @@ class Rexe
53
55
 
54
56
  def clear
55
57
  self.input_filespec = nil
56
- self.input_format = :none
57
- self.input_mode = :none
58
- self.output_format = :none
59
- self.loads = []
60
- self.requires = []
61
- self.log_format = :none
62
- self.noop = false
58
+ self.input_format = :none
59
+ self.input_mode = :none
60
+ self.output_format = :none
61
+ self.output_format_tty = :none
62
+ self.output_format_block = :none
63
+ self.loads = []
64
+ self.requires = []
65
+ self.log_format = :none
66
+ self.noop = false
63
67
  end
64
68
  end
65
69
 
@@ -173,69 +177,77 @@ class Rexe
173
177
 
174
178
 
175
179
  private def help_text
176
- <<~HEREDOC
177
-
178
- rexe -- Ruby Command Line Executor/Filter -- v#{VERSION} -- #{PROJECT_URL}
179
-
180
- Executes Ruby code on the command line,
181
- optionally automating management of standard input and standard output,
182
- and optionally parsing input and formatting output with YAML, JSON, etc.
183
-
184
- rexe [options] [Ruby source code]
185
-
186
- Options:
187
-
188
- -c --clear_options Clear all previous command line options specified up to now
189
- -f --input_file Use this file instead of stdin for preprocessed input;
190
- if filespec has a YAML and JSON file extension,
191
- sets input format accordingly and sets input mode to -mb
192
- -g --log_format FORMAT Log format, logs to stderr, defaults to -gn (none)
193
- (see -o for format options)
194
- -h, --help Print help and exit
195
- -i, --input_format FORMAT Input format, defaults to -in (None)
196
- -ij JSON
197
- -im Marshal
198
- -in None (default)
199
- -iy YAML
200
- -l, --load RUBY_FILE(S) Ruby file(s) to load, comma separated;
201
- ! to clear all, or precede a name with '-' to remove
202
- -m, --input_mode MODE Input preprocessing mode (determines what `self` will be)
203
- defaults to -mn (none)
204
- -ml line; each line is ingested as a separate string
205
- -me enumerator (each_line on STDIN or File)
206
- -mb big string; all lines combined into one string
207
- -mn none (default); no input preprocessing;
208
- self is an Object.new
209
- -n, --[no-]noop Do not execute the code (useful with -g);
210
- For true: yes, true, y, +; for false: no, false, n
211
- -o, --output_format FORMAT Output format, defaults to -on (no output):
212
- -oi Inspect
213
- -oj JSON
214
- -oJ Pretty JSON
215
- -om Marshal
216
- -on No Output (default)
217
- -op Puts
218
- -os to_s
219
- -oy YAML
220
- -r, --require REQUIRE(S) Gems and built-in libraries to require, comma separated;
221
- ! to clear all, or precede a name with '-' to remove
222
- -v, --version Prints version and exits
223
-
224
- ---------------------------------------------------------------------------------------
225
-
226
- In many cases you will need to enclose your source code in single or double quotes.
227
-
228
- If source code is not specified, it will default to 'self',
229
- which is most likely useful only in a filter mode (-ml, -me, -mb).
230
-
231
- If there is a .rexerc file in your home directory, it will be run as Ruby code
232
- before processing the input.
233
-
234
- If there is a REXE_OPTIONS environment variable, its content will be prepended
235
- to the command line so that you can specify options implicitly
236
- (e.g. `export REXE_OPTIONS="-r awesome_print,yaml"`)
180
+ unless @help_text
181
+ @help_text ||= <<~HEREDOC
182
+
183
+ rexe -- Ruby Command Line Executor/Filter -- v#{VERSION} -- #{PROJECT_URL}
184
+
185
+ Executes Ruby code on the command line,
186
+ optionally automating management of standard input and standard output,
187
+ and optionally parsing input and formatting output with YAML, JSON, etc.
188
+
189
+ rexe [options] [Ruby source code]
190
+
191
+ Options:
192
+
193
+ -c --clear_options Clear all previous command line options specified up to now
194
+ -f --input_file Use this file instead of stdin for preprocessed input;
195
+ if filespec has a YAML and JSON file extension,
196
+ sets input format accordingly and sets input mode to -mb
197
+ -g --log_format FORMAT Log format, logs to stderr, defaults to -gn (none)
198
+ (see -o for format options)
199
+ -h, --help Print help and exit
200
+ -i, --input_format FORMAT Input format, defaults to -in (None)
201
+ -ij JSON
202
+ -im Marshal
203
+ -in None (default)
204
+ -iy YAML
205
+ -l, --load RUBY_FILE(S) Ruby file(s) to load, comma separated;
206
+ ! to clear all, or precede a name with '-' to remove
207
+ -m, --input_mode MODE Input preprocessing mode (determines what `self` will be)
208
+ defaults to -mn (none)
209
+ -ml line; each line is ingested as a separate string
210
+ -me enumerator (each_line on STDIN or File)
211
+ -mb big string; all lines combined into one string
212
+ -mn none (default); no input preprocessing;
213
+ self is an Object.new
214
+ -n, --[no-]noop Do not execute the code (useful with -g);
215
+ For true: yes, true, y, +; for false: no, false, n
216
+ -o, --output_format FORMAT Output format, defaults to -on (no output):
217
+ -oi Inspect
218
+ -oj JSON
219
+ -oJ Pretty JSON
220
+ -om Marshal
221
+ -on No Output (default)
222
+ -op Puts
223
+ -os to_s
224
+ -oy YAML
225
+ If 2 letters are provided, 1st is for tty devices, 2nd for block
226
+ --project-url Outputs project URL on Github, then exits
227
+ -r, --require REQUIRE(S) Gems and built-in libraries to require, comma separated;
228
+ ! to clear all, or precede a name with '-' to remove
229
+ -v, --version Prints version and exits
230
+
231
+ ---------------------------------------------------------------------------------------
232
+
233
+ In many cases you will need to enclose your source code in single or double quotes.
234
+
235
+ If source code is not specified, it will default to 'self',
236
+ which is most likely useful only in a filter mode (-ml, -me, -mb).
237
+
238
+ If there is a .rexerc file in your home directory, it will be run as Ruby code
239
+ before processing the input.
240
+
241
+ If there is a REXE_OPTIONS environment variable, its content will be prepended
242
+ to the command line so that you can specify options implicitly
243
+ (e.g. `export REXE_OPTIONS="-r awesome_print,yaml"`)
237
244
 
238
245
  HEREDOC
246
+
247
+ @help_text.freeze
248
+ end
249
+
250
+ @help_text
239
251
  end
240
252
 
241
253
 
@@ -348,10 +360,11 @@ class Rexe
348
360
 
349
361
  parser.on('-o', '--output_format FORMAT',
350
362
  'Mode with which to format values for output (`-o` + [aijJmnpsy])') do |v|
351
-
352
- options.output_format = lookups.output_formats[v]
353
- if options.output_format.nil?
354
- raise("Output mode was '#{v}' but must be one of #{lookups.output_formats.keys}.")
363
+ options.output_format_tty = lookups.output_formats[v[0]]
364
+ options.output_format_block = lookups.output_formats[v[-1]]
365
+ options.output_format = ($stdout.tty? ? options.output_format_tty : options.output_format_block)
366
+ if [options.output_format_tty, options.output_format_block].include?(nil)
367
+ raise("Bad output mode '#{v}'; each must be one of #{lookups.output_formats.keys}.")
355
368
  end
356
369
  end
357
370
 
@@ -375,12 +388,17 @@ class Rexe
375
388
  exit(0)
376
389
  end
377
390
 
378
- # Undocumented feature
391
+ # Undocumented feature: open Github project with default web browser on a Mac
379
392
  parser.on('', '--open-project') do
380
393
  open_resource(PROJECT_URL)
381
394
  exit(0)
382
395
  end
383
396
 
397
+ parser.on('', '--project-url') do
398
+ puts PROJECT_URL
399
+ exit(0)
400
+ end
401
+
384
402
  end.parse!
385
403
 
386
404
  # We want to do this after all options have been processed because we don't want any clearing of the
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: 1.0.3
4
+ version: 1.3.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-04-16 00:00:00.000000000 Z
11
+ date: 2019-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print