opt_parse_builder 0.2.0 → 1.1.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/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +7 -7
- data/README.md +52 -12
- data/doc/publishing.md +42 -0
- data/examples/hello_world.rb +1 -1
- data/examples/lib/setup_example.rb +8 -0
- data/lib/opt_parse_builder/argument.rb +4 -0
- data/lib/opt_parse_builder/argument_builder.rb +37 -6
- data/lib/opt_parse_builder/footer_argument.rb +11 -0
- data/lib/opt_parse_builder/parser.rb +52 -8
- data/lib/opt_parse_builder/parser_builder.rb +1 -1
- data/lib/opt_parse_builder/version.rb +1 -1
- data/lib/opt_parse_builder.rb +2 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b030936035ec1d79b8d22024f239664a8b8bf47c7fc00ac80d7d183a49859126
|
|
4
|
+
data.tar.gz: 3b771b01a70ddfbf2d4109f2554558100e729cb994c464625e49b35652d364f4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0140ca5bf9a14f8efd29040e75902d627331ec4be3d8c89dd4010da75cf38fd1f1b55321c53e8b5ebb4aa4b6c3ba94905efe6c8249dd95aade6e670f58135c12
|
|
7
|
+
data.tar.gz: f7f76918a1fa34779168c0e398f9adac38b82cd51e799a99c9e28ba9f6c2bbedfa606d9221590c2a65d1652cb93ecfc0670104813ba8a541140a6ad2a0bda083
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby-3.4.
|
|
1
|
+
ruby-3.4.7
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
# Development
|
|
4
4
|
|
|
5
|
+
# 1.1.0 - 2025-11-28
|
|
6
|
+
|
|
7
|
+
* Add footer method for text at bottom of help output (recommended)
|
|
8
|
+
* Add footer: parameter to separator method
|
|
9
|
+
- separator(line, footer: true) - deprecated, emits warning
|
|
10
|
+
- separator(line, footer: false) - new positional behavior
|
|
11
|
+
- Provides clear migration path to v2.0.0
|
|
12
|
+
|
|
13
|
+
# 1.0.0 - 2025-11-28
|
|
14
|
+
|
|
15
|
+
* Declare API stability by bumping version to 1.0.0
|
|
16
|
+
* Update gems
|
|
17
|
+
* Update Ruby to 3.4.7
|
|
18
|
+
|
|
5
19
|
# 0.2.0 - 2025-07-06
|
|
6
20
|
|
|
7
21
|
* Update gems
|
data/Gemfile.lock
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
opt_parse_builder (
|
|
4
|
+
opt_parse_builder (1.1.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
9
|
diff-lcs (1.6.2)
|
|
10
|
-
rake (13.3.
|
|
11
|
-
rspec (3.13.
|
|
10
|
+
rake (13.3.1)
|
|
11
|
+
rspec (3.13.2)
|
|
12
12
|
rspec-core (~> 3.13.0)
|
|
13
13
|
rspec-expectations (~> 3.13.0)
|
|
14
14
|
rspec-mocks (~> 3.13.0)
|
|
15
|
-
rspec-core (3.13.
|
|
15
|
+
rspec-core (3.13.6)
|
|
16
16
|
rspec-support (~> 3.13.0)
|
|
17
17
|
rspec-expectations (3.13.5)
|
|
18
18
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
19
19
|
rspec-support (~> 3.13.0)
|
|
20
|
-
rspec-mocks (3.13.
|
|
20
|
+
rspec-mocks (3.13.7)
|
|
21
21
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
22
|
rspec-support (~> 3.13.0)
|
|
23
|
-
rspec-support (3.13.
|
|
23
|
+
rspec-support (3.13.6)
|
|
24
24
|
|
|
25
25
|
PLATFORMS
|
|
26
26
|
ruby
|
|
@@ -32,4 +32,4 @@ DEPENDENCIES
|
|
|
32
32
|
rspec (~> 3.10)
|
|
33
33
|
|
|
34
34
|
BUNDLED WITH
|
|
35
|
-
2.
|
|
35
|
+
2.7.2
|
data/README.md
CHANGED
|
@@ -62,7 +62,7 @@ arg_parser = OptParseBuilder.build_parser do |args|
|
|
|
62
62
|
arg.key :verbose
|
|
63
63
|
arg.on "-v", "--verbose", "Be verbose"
|
|
64
64
|
end
|
|
65
|
-
args.
|
|
65
|
+
args.footer "Some explanatory text at the bottom"
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
arg_values = arg_parser.parse!
|
|
@@ -262,27 +262,67 @@ Applicable builder methods:
|
|
|
262
262
|
|
|
263
263
|
Banner text can be added to any argument.
|
|
264
264
|
|
|
265
|
-
##
|
|
265
|
+
## Footer only
|
|
266
266
|
|
|
267
|
-
An argument with only
|
|
268
|
-
OptParseBuilder#
|
|
269
|
-
|
|
270
|
-
--help output.
|
|
267
|
+
An argument with only footer text (but see
|
|
268
|
+
OptParseBuilder#footer for the usual way to do this). Footer text
|
|
269
|
+
appears at the bottom of the --help output.
|
|
271
270
|
|
|
272
271
|
OptParseBuilder.build_argument do |arg|
|
|
273
|
-
arg.
|
|
274
|
-
arg.
|
|
275
|
-
arg.
|
|
272
|
+
arg.footer "Footer text at the bottom"
|
|
273
|
+
arg.footer "A second line of footer text"
|
|
274
|
+
arg.footer <<~FOOTER
|
|
276
275
|
A third line
|
|
277
276
|
A fourth line
|
|
278
|
-
|
|
277
|
+
FOOTER
|
|
279
278
|
end
|
|
280
279
|
|
|
281
280
|
Applicable builder methods:
|
|
282
281
|
|
|
283
|
-
*
|
|
282
|
+
* footer
|
|
284
283
|
|
|
285
|
-
|
|
284
|
+
Footer text can be added to any argument.
|
|
285
|
+
|
|
286
|
+
## Positional separator
|
|
287
|
+
|
|
288
|
+
A separator that appears between options in the --help output,
|
|
289
|
+
useful for grouping related options.
|
|
290
|
+
|
|
291
|
+
OptParseBuilder.build_argument do |arg|
|
|
292
|
+
arg.key :verbose
|
|
293
|
+
arg.on "-v", "--verbose", "Be verbose"
|
|
294
|
+
arg.separator "--- Advanced options ---", footer: false
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
The separator will appear immediately after the option it's
|
|
298
|
+
attached to, allowing you to divide your options into sections.
|
|
299
|
+
|
|
300
|
+
Applicable builder methods:
|
|
301
|
+
|
|
302
|
+
* separator (with footer: false parameter)
|
|
303
|
+
|
|
304
|
+
## Separator only (deprecated)
|
|
305
|
+
|
|
306
|
+
**Note:** Using `separator` without the `footer:` parameter is
|
|
307
|
+
deprecated in v1.1.0 and will change behavior in v2.0.0. Use
|
|
308
|
+
`footer` for text at the bottom, or `separator(text, footer: false)`
|
|
309
|
+
for positional text.
|
|
310
|
+
|
|
311
|
+
# Deprecated - emits warning
|
|
312
|
+
OptParseBuilder.build_argument do |arg|
|
|
313
|
+
arg.separator "Text at bottom"
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
# Recommended alternatives:
|
|
317
|
+
# For bottom text:
|
|
318
|
+
OptParseBuilder.build_argument do |arg|
|
|
319
|
+
arg.footer "Text at bottom"
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# For positional text:
|
|
323
|
+
OptParseBuilder.build_argument do |arg|
|
|
324
|
+
arg.separator "Between options", footer: false
|
|
325
|
+
end
|
|
286
326
|
|
|
287
327
|
## Constant value
|
|
288
328
|
|
data/doc/publishing.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Publishing a New Release
|
|
2
|
+
|
|
3
|
+
# Checklist
|
|
4
|
+
|
|
5
|
+
* Update `lib/opt_parse_builder/version.rb`
|
|
6
|
+
* Update `CHANGELOG.md` with version and date
|
|
7
|
+
* Run tests: `rake`
|
|
8
|
+
* Commit: `git commit -am "Bump version to X.X.X"`
|
|
9
|
+
* Release: `rake release`
|
|
10
|
+
* Verify at https://rubygems.org/gems/opt_parse_builder
|
|
11
|
+
|
|
12
|
+
# Notes
|
|
13
|
+
|
|
14
|
+
Semantic Versioning: MAJOR.MINOR.PATCH (breaking.feature.bugfix)
|
|
15
|
+
|
|
16
|
+
What `rake release` does:
|
|
17
|
+
|
|
18
|
+
* Builds the gem
|
|
19
|
+
* Creates git tag vX.X.X
|
|
20
|
+
* Pushes tag to GitHub
|
|
21
|
+
* Publishes gem to rubygems.org
|
|
22
|
+
|
|
23
|
+
Dry run: `gem_push=no rake release` (tags but doesn't publish)
|
|
24
|
+
|
|
25
|
+
# Troubleshooting
|
|
26
|
+
|
|
27
|
+
No RubyGems credentials: `gem signin`
|
|
28
|
+
|
|
29
|
+
Release failed mid-way:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
git tag -d vX.X.X # Delete local tag
|
|
33
|
+
git push origin :vX.X.X # Delete remote tag
|
|
34
|
+
rake release # Try again
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Manual publish (if rake release fails):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
gem build opt_parse_builder.gemspec
|
|
41
|
+
gem push opt_parse_builder-X.X.X.gem
|
|
42
|
+
```
|
data/examples/hello_world.rb
CHANGED
|
@@ -16,6 +16,7 @@ module OptParseBuilder
|
|
|
16
16
|
@operand_help_name = nil
|
|
17
17
|
@banner_lines = []
|
|
18
18
|
@separator_lines = []
|
|
19
|
+
@footer_lines = []
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
# Set the argument's key. Accepts either a string or a symbol.
|
|
@@ -115,11 +116,38 @@ module OptParseBuilder
|
|
|
115
116
|
# may call this more than once; each call adds another line of
|
|
116
117
|
# text to the separator.
|
|
117
118
|
#
|
|
119
|
+
# The footer: parameter controls where the text appears:
|
|
120
|
+
# * footer: true (default in v1.x) - text appears at bottom
|
|
121
|
+
# (DEPRECATED: use footer method instead)
|
|
122
|
+
# * footer: false - text appears positionally between options
|
|
123
|
+
# (will be default in v2.0.0)
|
|
124
|
+
#
|
|
118
125
|
# Any type of argument may have separator text.
|
|
119
126
|
#
|
|
120
|
-
# See also OptParseBuilder#separator
|
|
121
|
-
def separator(line)
|
|
122
|
-
|
|
127
|
+
# See also OptParseBuilder#separator and OptParseBuilder#footer
|
|
128
|
+
def separator(line, footer: true)
|
|
129
|
+
if footer
|
|
130
|
+
warn "separator with footer text is deprecated and will" +
|
|
131
|
+
" become positional in v2.0.0. Use footer(line) instead or" +
|
|
132
|
+
" separator(line, footer: false) for positional."
|
|
133
|
+
@footer_lines << line
|
|
134
|
+
else
|
|
135
|
+
@separator_lines << line
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Add to the footer text shown at the bottom of --help output.
|
|
140
|
+
# You may call this more than once; each call adds another line
|
|
141
|
+
# of text to the footer.
|
|
142
|
+
#
|
|
143
|
+
# This is the recommended way to add text at the bottom of help
|
|
144
|
+
# output in v1.1.0 and later.
|
|
145
|
+
#
|
|
146
|
+
# Any type of argument may have footer text.
|
|
147
|
+
#
|
|
148
|
+
# See also OptParseBuilder#footer
|
|
149
|
+
def footer(line)
|
|
150
|
+
@footer_lines << line
|
|
123
151
|
end
|
|
124
152
|
|
|
125
153
|
# Declare the operand to be an optional operand. An optional
|
|
@@ -155,9 +183,6 @@ module OptParseBuilder
|
|
|
155
183
|
unless @banner_lines.empty?
|
|
156
184
|
bundle << BannerArgument.new(@banner_lines)
|
|
157
185
|
end
|
|
158
|
-
unless @separator_lines.empty?
|
|
159
|
-
bundle << SeparatorArgument.new(@separator_lines)
|
|
160
|
-
end
|
|
161
186
|
if !@on.empty?
|
|
162
187
|
bundle << OptionArgument.new(@key, @default, @on, @handler)
|
|
163
188
|
elsif @operand_class
|
|
@@ -171,6 +196,12 @@ module OptParseBuilder
|
|
|
171
196
|
bundle << ConstantArgument.new(@key, @default)
|
|
172
197
|
end
|
|
173
198
|
end
|
|
199
|
+
unless @separator_lines.empty?
|
|
200
|
+
bundle << SeparatorArgument.new(@separator_lines)
|
|
201
|
+
end
|
|
202
|
+
unless @footer_lines.empty?
|
|
203
|
+
bundle << FooterArgument.new(@footer_lines)
|
|
204
|
+
end
|
|
174
205
|
bundle.simplify
|
|
175
206
|
end
|
|
176
207
|
|
|
@@ -151,14 +151,20 @@ module OptParseBuilder
|
|
|
151
151
|
# Although it's called a "line," you can embed new-lines in it so
|
|
152
152
|
# that it is actually more than one line.
|
|
153
153
|
#
|
|
154
|
+
# The footer: parameter controls where the text appears:
|
|
155
|
+
# * footer: true (default in v1.x) - text appears at bottom
|
|
156
|
+
# (DEPRECATED: use footer method instead)
|
|
157
|
+
# * footer: false - text appears positionally between options
|
|
158
|
+
# (will be default in v2.0.0)
|
|
159
|
+
#
|
|
154
160
|
# This example:
|
|
155
161
|
#
|
|
156
162
|
# arg_parser = OptParseBuilder.build_parser do |args|
|
|
157
|
-
# args.
|
|
158
|
-
# args.
|
|
163
|
+
# args.footer "Here I explain more about my program"
|
|
164
|
+
# args.footer <<~FOOTER
|
|
159
165
|
# For such a small program,
|
|
160
166
|
# it has a lot of text at the end.
|
|
161
|
-
#
|
|
167
|
+
# FOOTER
|
|
162
168
|
# end
|
|
163
169
|
# arg_parser.parse!(["--help"])
|
|
164
170
|
#
|
|
@@ -168,9 +174,42 @@ module OptParseBuilder
|
|
|
168
174
|
# Here I explain more about my program
|
|
169
175
|
# For such a small program,
|
|
170
176
|
# it has a lot of text at the end.
|
|
171
|
-
def separator(line)
|
|
177
|
+
def separator(line, footer: true)
|
|
172
178
|
add do |arg|
|
|
173
|
-
arg.separator(line)
|
|
179
|
+
arg.separator(line, footer: footer)
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Add a line to the footer. The footer is text that appears
|
|
184
|
+
# at the bottom of the help text.
|
|
185
|
+
#
|
|
186
|
+
# A new-line will automatically be added to the end of the line.
|
|
187
|
+
# Although it's called a "line," you can embed new-lines in it so
|
|
188
|
+
# that it is actually more than one line.
|
|
189
|
+
#
|
|
190
|
+
# This is the recommended way to add text at the bottom of help
|
|
191
|
+
# output in v1.1.0 and later.
|
|
192
|
+
#
|
|
193
|
+
# This example:
|
|
194
|
+
#
|
|
195
|
+
# arg_parser = OptParseBuilder.build_parser do |args|
|
|
196
|
+
# args.footer "Here I explain more about my program"
|
|
197
|
+
# args.footer <<~FOOTER
|
|
198
|
+
# For such a small program,
|
|
199
|
+
# it has a lot of text at the end.
|
|
200
|
+
# FOOTER
|
|
201
|
+
# end
|
|
202
|
+
# arg_parser.parse!(["--help"])
|
|
203
|
+
#
|
|
204
|
+
# Results in `--help` output like this:
|
|
205
|
+
#
|
|
206
|
+
# Usage: example [options] <path>
|
|
207
|
+
# Here I explain more about my program
|
|
208
|
+
# For such a small program,
|
|
209
|
+
# it has a lot of text at the end.
|
|
210
|
+
def footer(line)
|
|
211
|
+
add do |arg|
|
|
212
|
+
arg.footer(line)
|
|
174
213
|
end
|
|
175
214
|
end
|
|
176
215
|
|
|
@@ -313,12 +352,17 @@ module OptParseBuilder
|
|
|
313
352
|
def optparse
|
|
314
353
|
op = OptParse.new
|
|
315
354
|
op.banner = banner_prefix + op.banner + banner_suffix
|
|
316
|
-
@arguments.each
|
|
317
|
-
|
|
318
|
-
|
|
355
|
+
@arguments.each do |arg|
|
|
356
|
+
arg.apply_option(op)
|
|
357
|
+
arg.separator_lines.each do |line|
|
|
319
358
|
op.separator(line)
|
|
320
359
|
end
|
|
321
360
|
end
|
|
361
|
+
@arguments.each do |argument|
|
|
362
|
+
argument.footer_lines.each do |line|
|
|
363
|
+
op.on_tail(line)
|
|
364
|
+
end
|
|
365
|
+
end
|
|
322
366
|
op
|
|
323
367
|
end
|
|
324
368
|
|
data/lib/opt_parse_builder.rb
CHANGED
|
@@ -8,6 +8,7 @@ require_relative "opt_parse_builder/argument_values"
|
|
|
8
8
|
require_relative "opt_parse_builder/banner_argument"
|
|
9
9
|
require_relative "opt_parse_builder/constant_argument"
|
|
10
10
|
require_relative "opt_parse_builder/errors"
|
|
11
|
+
require_relative "opt_parse_builder/footer_argument"
|
|
11
12
|
require_relative "opt_parse_builder/formats_operand_name"
|
|
12
13
|
require_relative "opt_parse_builder/has_value"
|
|
13
14
|
require_relative "opt_parse_builder/null_argument"
|
|
@@ -53,7 +54,7 @@ require_relative "opt_parse_builder/stable_sort"
|
|
|
53
54
|
# arg.on "--size=N", Integer
|
|
54
55
|
# arg.on "Size in bytes (default _DEFAULT_)"
|
|
55
56
|
# end
|
|
56
|
-
# parser.
|
|
57
|
+
# parser.footer "Explanatory text at the bottom"
|
|
57
58
|
# end
|
|
58
59
|
# arg_values = arg_parser.parse!
|
|
59
60
|
# p arg_values.quiet # nil or true
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opt_parse_builder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Wayne Conrad
|
|
@@ -71,7 +71,9 @@ files:
|
|
|
71
71
|
- LICENSE
|
|
72
72
|
- README.md
|
|
73
73
|
- Rakefile
|
|
74
|
+
- doc/publishing.md
|
|
74
75
|
- examples/hello_world.rb
|
|
76
|
+
- examples/lib/setup_example.rb
|
|
75
77
|
- lib/opt_parse_builder.rb
|
|
76
78
|
- lib/opt_parse_builder/argument.rb
|
|
77
79
|
- lib/opt_parse_builder/argument_builder.rb
|
|
@@ -81,6 +83,7 @@ files:
|
|
|
81
83
|
- lib/opt_parse_builder/banner_argument.rb
|
|
82
84
|
- lib/opt_parse_builder/constant_argument.rb
|
|
83
85
|
- lib/opt_parse_builder/errors.rb
|
|
86
|
+
- lib/opt_parse_builder/footer_argument.rb
|
|
84
87
|
- lib/opt_parse_builder/formats_operand_name.rb
|
|
85
88
|
- lib/opt_parse_builder/has_value.rb
|
|
86
89
|
- lib/opt_parse_builder/null_argument.rb
|
|
@@ -117,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
117
120
|
- !ruby/object:Gem::Version
|
|
118
121
|
version: '0'
|
|
119
122
|
requirements: []
|
|
120
|
-
rubygems_version: 3.6.
|
|
123
|
+
rubygems_version: 3.6.9
|
|
121
124
|
specification_version: 4
|
|
122
125
|
summary: Builder DSL for optparse, with more
|
|
123
126
|
test_files: []
|