rexe 1.5.1 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +7 -7
  4. data/exe/rexe +62 -37
  5. data/rexe.gemspec +10 -2
  6. metadata +10 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '036597bf795aea3d05206bec898b2688dc1b75cf51c2dec772574a86734f56ef'
4
- data.tar.gz: 6d404ef04a3fdcf8913e654da1cb71e18191f3796e70f0da2dc249f467f88f5a
3
+ metadata.gz: 7d4ad1a24022659314b09d706db797d17702d6b879b4b52d0d4068b7fef4ef9c
4
+ data.tar.gz: 04b6759f33142d6e738bd12ce0bad997385f77c02c7e0537ea5f3c609df8ef7b
5
5
  SHA512:
6
- metadata.gz: 6002bbc565faf3861ec08752b22160453b2b35dbab126e4e7d53b9e4e7b68da49545fb615f48eb4a8bddc087943cf33572e36521b38d1e0fe12a17812e0ea4a8
7
- data.tar.gz: 63cfec0e25406005aa3c030376755333842f294530ee96fc7d9344460f9b7efbd4c7380eeffed689905bf2331c836b8935e297278237cb8721ba19e0a19c81e9
6
+ metadata.gz: 7a51a900c81e65878e13a795708c35e57d41f7226300932bea17105707aa03f9b5246e386ecdb7e3d437361614ccbdbaab63b7fb1b4c6bc59ee28bbd33dcd18a
7
+ data.tar.gz: cc4acaa0817872e3e9ec7960246c721152c7311708abd8bed7bf9e206332c8c6bf579d876c0240d2a98a1780eaade154fd7412b3c3e5fa28d5f8383308ea0323
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## rexe -- Ruby Command Line Executor/Filter
2
2
 
3
+ ### 1.7.0
4
+
5
+ * Replace amazing_print dependency with awesome_print.
6
+ * Effectively disable `try` method, i.e. print stack trace on errors.
7
+ * In `try` method, rescue StandardError instead of Exception.
8
+
9
+
10
+ ### 1.6.0
11
+
12
+ * Replace calls to `exists?`, which has been removed, with `exist?`.
13
+ * Add warning messages to stderr for unspecified options (input/output format, input mode),
14
+ but only when logging is disabled.
15
+
3
16
  ### 1.5.1
4
17
 
5
18
  * Change string concatenations using << to creation of new strings with += to accommodate default-frozen strings.
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.5.0 -- https://github.com/keithrbennett/rexe
76
+ rexe -- Ruby Command Line Executor/Filter -- v1.7.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,
@@ -135,7 +135,7 @@ before processing the input.
135
135
 
136
136
  If there is a REXE_OPTIONS environment variable, its content will be prepended
137
137
  to the command line so that you can specify options implicitly
138
- (e.g. `export REXE_OPTIONS="-r amazing_print,yaml"`)
138
+ (e.g. `export REXE_OPTIONS="-r awesome_print,yaml"`)
139
139
  ```
140
140
 
141
141
  ### Simplifying the Rexe Invocation
@@ -239,11 +239,11 @@ $ echo $EUR_RATES_JSON | rexe -gy -ij -mb -oa -n self
239
239
  :input_format: :json
240
240
  :input_mode: :one_big_string
241
241
  :loads: []
242
- :output_format: :amazing_print
243
- :output_format_tty: :amazing_print
244
- :output_format_block: :amazing_print
242
+ :output_format: :awesome_print
243
+ :output_format_tty: :awesome_print
244
+ :output_format_block: :awesome_print
245
245
  :requires:
246
- - amazing_print
246
+ - awesome_print
247
247
  - json
248
248
  - yaml
249
249
  :log_format: :yaml
@@ -741,7 +741,7 @@ For consistency with the `ruby` interpreter, rexe supports requires with the `-r
741
741
 
742
742
  ```bash
743
743
  vvvvvvvvvvvvvvvvvv
744
- $ echo $EUR_RATES_JSON | rexe -r json,amazing_print 'ap JSON.parse(STDIN.read)'
744
+ $ echo $EUR_RATES_JSON | rexe -r json,awesome_print 'ap JSON.parse(STDIN.read)'
745
745
  ^^^^^^^^^^^^^^^^^^
746
746
  ```
747
747
 
data/exe/rexe CHANGED
@@ -15,24 +15,26 @@ require 'shellwords'
15
15
 
16
16
  class Rexe
17
17
 
18
- VERSION = '1.5.1'
18
+ VERSION = '1.7.0'
19
19
 
20
20
  PROJECT_URL = 'https://github.com/keithrbennett/rexe'
21
21
 
22
22
 
23
23
  module Helpers
24
24
 
25
- # Try executing code. If error raised, print message (but not stack trace) & exit -1.
25
+ # Originally the entire run was wrapped in this rescue to make error output more concise.
26
+ # However, I am concerned that hiding the stack trace will make it harder to debug,
27
+ # and be worse than the ugliness of showing it when it is not needed. So, I am commenting
28
+ # out the rescue for now, and will see how it goes. If you have any opinions on this,
29
+ # please let me know at https://github.com/keithrbennett/rexe/issues/5 .
30
+ #
31
+ # (disabled) Try executing code. If error raised, print message (but not stack trace) & exit -1.
26
32
  def try
27
- begin
28
- yield
29
- rescue Exception => e
30
- unless e.class == SystemExit
31
- $stderr.puts("rexe: #{e}")
32
- $stderr.puts("Use the -h option to get help.")
33
- exit(-1)
34
- end
35
- end
33
+ yield
34
+ # rescue StandardError => e
35
+ # $stderr.puts("rexe ERROR: #{e}")
36
+ # $stderr.puts('Use the -h option to get help.')
37
+ # exit(-1)
36
38
  end
37
39
  end
38
40
 
@@ -57,7 +59,7 @@ class Rexe
57
59
 
58
60
 
59
61
  def clear
60
- self.input_filespec = nil
62
+ self.input_filespec = nil
61
63
  self.input_format = :none
62
64
  self.input_mode = :none
63
65
  self.output_format = :none
@@ -71,9 +73,6 @@ class Rexe
71
73
  end
72
74
 
73
75
 
74
-
75
-
76
-
77
76
  class Lookups
78
77
  def input_modes
79
78
  @input_modes ||= {
@@ -107,7 +106,7 @@ class Rexe
107
106
 
108
107
  def output_formats
109
108
  @output_formats ||= {
110
- 'a' => :amazing_print,
109
+ 'a' => :awesome_print,
111
110
  'i' => :inspect,
112
111
  'j' => :json,
113
112
  'J' => :pretty_json,
@@ -123,7 +122,7 @@ class Rexe
123
122
 
124
123
  def formatters
125
124
  @formatters ||= {
126
- amazing_print: ->(obj) { obj.ai + "\n" },
125
+ awesome_print: ->(obj) { obj.ai + "\n" },
127
126
  inspect: ->(obj) { obj.inspect + "\n" },
128
127
  json: ->(obj) { obj.to_json },
129
128
  marshal: ->(obj) { Marshal.dump(obj) },
@@ -141,7 +140,7 @@ class Rexe
141
140
  @format_requires ||= {
142
141
  json: 'json',
143
142
  pretty_json: 'json',
144
- amazing_print: 'amazing_print',
143
+ awesome_print: 'awesome_print',
145
144
  pretty_print: 'pp',
146
145
  yaml: 'yaml'
147
146
  }
@@ -149,7 +148,6 @@ class Rexe
149
148
  end
150
149
 
151
150
 
152
-
153
151
  class CommandLineParser
154
152
 
155
153
  include Helpers
@@ -245,9 +243,9 @@ class Rexe
245
243
 
246
244
  If there is a REXE_OPTIONS environment variable, its content will be prepended
247
245
  to the command line so that you can specify options implicitly
248
- (e.g. `export REXE_OPTIONS="-r amazing_print,yaml"`)
246
+ (e.g. `export REXE_OPTIONS="-r awesome_print,yaml"`)
249
247
 
250
- HEREDOC
248
+ HEREDOC
251
249
 
252
250
  @help_text.freeze
253
251
  end
@@ -261,7 +259,7 @@ class Rexe
261
259
  extension = File.extname(filespec).downcase
262
260
  if extension == '.json'
263
261
  :json
264
- elsif extension == '.yml' || extension == '.yaml'
262
+ elsif %w{.yml .yaml}.include?(extension)
265
263
  :yaml
266
264
  else
267
265
  :none
@@ -289,9 +287,32 @@ class Rexe
289
287
 
290
288
  prepend_environment_options
291
289
 
290
+ input_mode_specified = false
291
+ input_format_specified = false
292
+ output_format_specified = false
293
+
294
+ report_unspecified_options = -> do
295
+ messages = []
296
+
297
+ unless input_mode_specified
298
+ messages << 'Input mode not specified. Defaulting to -mn (none).'
299
+ end
300
+ unless input_format_specified
301
+ messages << 'Input format not specified. Defaulting to -in (none).'
302
+ end
303
+ unless output_format_specified
304
+ messages << 'Output mode not specified. Defaulting to -on (none).'
305
+ end
306
+
307
+ if messages.any?
308
+ $stderr.puts(messages.join("\n"))
309
+ $stderr.puts("See help (run with -h) for more information.\n\n")
310
+ end
311
+ end
312
+
292
313
  OptionParser.new do |parser|
293
314
 
294
- parser.on('-c', '--clear_options', "Clear all previous command line options") do |v|
315
+ parser.on('-c', '--clear_options', 'Clear all previous command line options') do |v|
295
316
  options.clear
296
317
  end
297
318
 
@@ -302,8 +323,10 @@ class Rexe
302
323
  end
303
324
  options.input_filespec = v
304
325
  options.input_format = autodetect_file_format(v)
326
+ input_format_specified = true
305
327
  if [:json, :yaml].include?(options.input_format)
306
328
  options.input_mode = :one_big_string
329
+ input_mode_specified = true
307
330
  end
308
331
  end
309
332
 
@@ -314,7 +337,7 @@ class Rexe
314
337
  end
315
338
  end
316
339
 
317
- parser.on("-h", "--help", "Show help") do |_help_requested|
340
+ parser.on("-h", "--help", 'Show help') do |_help_requested|
318
341
  puts help_text
319
342
  exit
320
343
  end
@@ -326,6 +349,7 @@ class Rexe
326
349
  if options.input_format.nil?
327
350
  raise("Input mode was '#{v}' but must be one of #{lookups.input_formats.keys}.")
328
351
  end
352
+ input_format_specified = true
329
353
  end
330
354
 
331
355
  parser.on('-l', '--load RUBY_FILE(S)', 'Ruby file(s) to load, comma separated, or ! to clear') do |v|
@@ -335,7 +359,7 @@ class Rexe
335
359
  loadfiles = v.split(',').map(&:strip).map { |s| File.expand_path(s) }
336
360
  removes, adds = loadfiles.partition { |filespec| filespec[0] == '-' }
337
361
 
338
- existent, nonexistent = adds.partition { |filespec| File.exists?(filespec) }
362
+ existent, nonexistent = adds.partition { |filespec| File.exist?(filespec) }
339
363
  if nonexistent.any?
340
364
  raise("\nDid not find the following files to load: #{nonexistent}\n\n")
341
365
  else
@@ -353,6 +377,7 @@ class Rexe
353
377
  if options.input_mode.nil?
354
378
  raise("Input mode was '#{v}' but must be one of #{lookups.input_modes.keys}.")
355
379
  end
380
+ input_mode_specified = true
356
381
  end
357
382
 
358
383
  # See https://stackoverflow.com/questions/54576873/ruby-optionparser-short-code-for-boolean-option
@@ -371,6 +396,7 @@ class Rexe
371
396
  if [options.output_format_tty, options.output_format_block].include?(nil)
372
397
  raise("Bad output mode '#{v}'; each must be one of #{lookups.output_formats.keys}.")
373
398
  end
399
+ output_format_specified = true
374
400
  end
375
401
 
376
402
  parser.on('-r', '--require REQUIRE(S)',
@@ -413,6 +439,7 @@ class Rexe
413
439
  options.requires = options.requires.sort.uniq
414
440
  options.loads.uniq!
415
441
 
442
+ report_unspecified_options.() if options.log_format == :none
416
443
  options
417
444
 
418
445
  end
@@ -436,7 +463,7 @@ class Rexe
436
463
 
437
464
  private def load_global_config_if_exists
438
465
  filespec = File.join(Dir.home, '.rexerc')
439
- load(filespec) if File.exists?(filespec)
466
+ load(filespec) if File.exist?(filespec)
440
467
  end
441
468
 
442
469
 
@@ -508,17 +535,15 @@ class Rexe
508
535
  # Bypasses Bundler's restriction on loading gems
509
536
  # (see https://stackoverflow.com/questions/55144094/bundler-doesnt-permit-using-gems-in-project-home-directory)
510
537
  private def require!(the_require)
511
- begin
538
+ require the_require
539
+ rescue LoadError => error
540
+ gem_path = `gem which #{the_require}`
541
+ if gem_path.chomp.strip.empty?
542
+ raise error # re-raise the error, can't fix it
543
+ else
544
+ load_dir = File.dirname(gem_path)
545
+ $LOAD_PATH += load_dir
512
546
  require the_require
513
- rescue LoadError => error
514
- gem_path = `gem which #{the_require}`
515
- if gem_path.chomp.strip.empty?
516
- raise error # re-raise the error, can't fix it
517
- else
518
- load_dir = File.dirname(gem_path)
519
- $LOAD_PATH += load_dir
520
- require the_require
521
- end
522
547
  end
523
548
  end
524
549
 
@@ -566,4 +591,4 @@ def bundler_run(&block)
566
591
  end
567
592
 
568
593
 
569
- bundler_run { Rexe::Main.new.call }
594
+ bundler_run { Rexe::Main.new.call }
data/rexe.gemspec CHANGED
@@ -3,6 +3,9 @@ Gem::Specification.new do |spec|
3
3
  spec.name = "rexe"
4
4
 
5
5
  spec.version = -> do
6
+ # This is a bit of a kludge. If there is a commented out VERSION line preceding the active line,
7
+ # this will read the commented line.
8
+ # TODO: Ignore comment lines.
6
9
  rexe_file = File.join(File.dirname(__FILE__), 'exe', 'rexe')
7
10
  version_line = File.readlines(rexe_file).grep(/\s*VERSION\s*=\s*'/).first.chomp
8
11
  version_line.match(/'(.+)'/)[0].gsub("'", '')
@@ -38,11 +41,16 @@ Gem::Specification.new do |spec|
38
41
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
39
42
  spec.require_paths = ["lib"]
40
43
 
41
- spec.add_dependency "amazing_print"
44
+ spec.add_dependency "awesome_print"
42
45
 
43
46
  spec.add_development_dependency "bundler", "~> 2.0"
44
47
  spec.add_development_dependency "os"
45
48
  spec.add_development_dependency "rake", "~> 12.3"
46
- spec.add_development_dependency "rspec", "~> 3.0"
49
+ spec.add_development_dependency "rspec", "~> 3.12"
47
50
 
51
+ # Remove this message (added November 2023) later (maybe July 2024).
52
+ spec.post_install_message = <<~MESSAGE
53
+ Starting with v1.7.0, awesome_print is now used instead of amazing_print
54
+ for fancy human readable output.
55
+ MESSAGE
48
56
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rexe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Bennett
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-10 00:00:00.000000000 Z
11
+ date: 2023-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: amazing_print
14
+ name: awesome_print
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.0'
75
+ version: '3.12'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.0'
82
+ version: '3.12'
83
83
  description: Ruby Command Line Executor
84
84
  email:
85
85
  - keithrbennett@gmail.com
@@ -110,7 +110,8 @@ metadata:
110
110
  homepage_uri: https://github.com/keithrbennett/rexe
111
111
  source_code_uri: https://github.com/keithrbennett/rexe
112
112
  changelog_uri: https://github.com/keithrbennett/rexe/blob/master/README.md
113
- post_install_message:
113
+ post_install_message: "Starting with v1.7.0, awesome_print is now used instead of
114
+ amazing_print \nfor fancy human readable output.\n"
114
115
  rdoc_options: []
115
116
  require_paths:
116
117
  - lib
@@ -125,8 +126,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
126
  - !ruby/object:Gem::Version
126
127
  version: '0'
127
128
  requirements: []
128
- rubygems_version: 3.1.2
129
- signing_key:
129
+ rubygems_version: 3.4.22
130
+ signing_key:
130
131
  specification_version: 4
131
132
  summary: Ruby Command Line Executor
132
133
  test_files: []