shellopts 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/TODO +1 -0
- data/lib/shellopts/grammar/command.rb +0 -1
- data/lib/shellopts/utils.rb +16 -0
- data/lib/shellopts/version.rb +1 -1
- data/lib/shellopts.rb +24 -11
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 710c9651cae2494969fe031b4d8a91bbcebd123c8d395b512bec5b193c50e6ea
|
4
|
+
data.tar.gz: e2a4901ea784ec6331ccd65ef4df58daf04aba44c0c395f736da27eee14f8f12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad85e178173ba17e7cfc0b452cc1bcdd50e7c17374885b8aecddd4495e04a5492c14bdecfdd13445738e63c8bfa2434c3f0957ab1e7d803dc18ba42722726761
|
7
|
+
data.tar.gz: be53d32e0fdcbcf4caee01762e5bb5d6b8452ffeaf6ae7f65e9746cf7a222aa65ab38ca8dd4db8de91c6f0507e4fc9df88d30c286e29a83d994d020bae4759a1
|
data/README.md
CHANGED
@@ -257,8 +257,8 @@ system (eg. disk full) and omits the usage summary
|
|
257
257
|
```
|
258
258
|
|
259
259
|
The methods are defined as instance methods on `ShellOpts::ShellOpts` and as
|
260
|
-
class methods on `ShellOpts`.
|
261
|
-
|
260
|
+
class methods on `ShellOpts`. They can also be included in the global scope by
|
261
|
+
`include ShellOpts::Utils`
|
262
262
|
|
263
263
|
## Example
|
264
264
|
|
data/TODO
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
module ShellOpts
|
3
|
+
# Use `include ShellOpts::Utils` to include ShellOpts utility methods in the
|
4
|
+
# global namespace
|
5
|
+
module Utils
|
6
|
+
# Forwards to `ShellOpts.error`
|
7
|
+
def error(*msgs)
|
8
|
+
::ShellOpts.error(*msgs)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Forwards to `ShellOpts.fail`
|
12
|
+
def fail(*msgs)
|
13
|
+
::ShellOpts.fail(*msgs)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/shellopts/version.rb
CHANGED
data/lib/shellopts.rb
CHANGED
@@ -7,6 +7,9 @@ require 'shellopts/parser.rb'
|
|
7
7
|
# library API consists of the methods {ShellOpts.process}, {ShellOpts.error},
|
8
8
|
# and {ShellOpts.fail} and the result class {ShellOpts::ShellOpts}
|
9
9
|
#
|
10
|
+
# ShellOpts inject the constant PROGRAM into the global scope. It contains the
|
11
|
+
# name of the program
|
12
|
+
#
|
10
13
|
module ShellOpts
|
11
14
|
# Process command line options and arguments. #process takes a usage string
|
12
15
|
# defining the options and the array of command line arguments to be parsed
|
@@ -76,7 +79,7 @@ module ShellOpts
|
|
76
79
|
# shellopts.args.each { |arg| ... }
|
77
80
|
# shellopts.error("Something went wrong")
|
78
81
|
#
|
79
|
-
def self.process(usage, argv, program_name:
|
82
|
+
def self.process(usage, argv, program_name: PROGRAM, &block)
|
80
83
|
if !block_given?
|
81
84
|
ShellOpts.new(usage, argv, program_name: program_name)
|
82
85
|
else
|
@@ -93,15 +96,21 @@ module ShellOpts
|
|
93
96
|
@shellopts = nil
|
94
97
|
end
|
95
98
|
|
96
|
-
# Print error message and usage string and exit with status 1.
|
97
|
-
#
|
99
|
+
# Print error message and usage string and exit with status 1. It use the
|
100
|
+
# current ShellOpts object if defined. This method should be called in
|
101
|
+
# response to user-errors (eg. specifying an illegal option)
|
98
102
|
def self.error(*msgs)
|
99
|
-
@shellopts&.
|
103
|
+
program = @shellopts&.program_name || PROGRAM
|
104
|
+
usage = @shellopts&.usage || (defined?(USAGE) && USAGE ? Grammar.compile(PROGRAM, USAGE).usage : nil)
|
105
|
+
emit_and_exit(program, usage, *msgs)
|
100
106
|
end
|
101
107
|
|
102
|
-
# Print error message and exit with status 1.
|
108
|
+
# Print error message and exit with status 1. It use the current ShellOpts
|
109
|
+
# object if defined. This method should not be called in response to
|
110
|
+
# user-errors but system errors (like disk full)
|
103
111
|
def self.fail(*msgs)
|
104
|
-
@shellopts&.
|
112
|
+
program = @shellopts&.program_name || PROGRAM
|
113
|
+
emit_and_exit(program, nil, *msgs)
|
105
114
|
end
|
106
115
|
|
107
116
|
# The compilation object
|
@@ -162,16 +171,13 @@ module ShellOpts
|
|
162
171
|
# should be called in response to user-errors (eg. specifying an illegal
|
163
172
|
# option)
|
164
173
|
def error(*msgs)
|
165
|
-
|
166
|
-
$stderr.puts "Usage: #{program_name} #{usage}"
|
167
|
-
exit 1
|
174
|
+
::ShellOpts.emit_and_exit(program_name, usage, msgs)
|
168
175
|
end
|
169
176
|
|
170
177
|
# Print error message and exit with status 1. This method should not be
|
171
178
|
# called in response to user-errors but system errors (like disk full)
|
172
179
|
def fail(*msgs)
|
173
|
-
|
174
|
-
exit 1
|
180
|
+
::ShellOpts.emit_and_exit(program_name, nil, msgs)
|
175
181
|
end
|
176
182
|
end
|
177
183
|
|
@@ -191,5 +197,12 @@ module ShellOpts
|
|
191
197
|
|
192
198
|
private
|
193
199
|
@shellopts = nil
|
200
|
+
|
201
|
+
def self.emit_and_exit(program, usage, *msgs)
|
202
|
+
$stderr.puts "#{program}: #{msgs.join}"
|
203
|
+
$stderr.puts "Usage: #{program} #{usage}" if usage
|
204
|
+
exit 1
|
205
|
+
end
|
194
206
|
end
|
195
207
|
|
208
|
+
PROGRAM = File.basename($PROGRAM_NAME)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shellopts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/shellopts/grammar/option.rb
|
116
116
|
- lib/shellopts/grammar/program.rb
|
117
117
|
- lib/shellopts/parser.rb
|
118
|
+
- lib/shellopts/utils.rb
|
118
119
|
- lib/shellopts/version.rb
|
119
120
|
- shellopts.gemspec
|
120
121
|
homepage: http://github.com/clrgit/shellopts
|