options_parser 1.0.1 → 1.0.2
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/.git-com.yaml +7 -2
- data/README.md +10 -0
- data/lib/options_parser/option.rb +1 -1
- data/lib/options_parser/parser.rb +34 -9
- data/lib/options_parser/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 46f025bfa171807935c0c1c48163f76546bd01a0609ed9f6646a741e2927e8df
|
|
4
|
+
data.tar.gz: 55b6e9162403c49b91b42aa432599cedee4a431a220228d504c16d1d5dac961c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 737724e68b457e0c3350c4e93e260f046bd5b8bea3a89f6909e6dabe07c37b87ce19dff8a9aaf43af7f59a8105a3b7d8c71407d357381cd29777bc363d49c364
|
|
7
|
+
data.tar.gz: '0113975a645f8105d746c4f455d6bf979b1d521e97a2f5d8f560ab43c41bcb569b970fdc883e440dae05f6b380ca302e13050eec1d9aebb7ce4bab0a2dd08561'
|
data/.git-com.yaml
CHANGED
|
@@ -16,13 +16,11 @@ commit-title:
|
|
|
16
16
|
placeholder: Commit Title
|
|
17
17
|
type: text
|
|
18
18
|
commit-description:
|
|
19
|
-
after-string: ""
|
|
20
19
|
allow-empty: true
|
|
21
20
|
destination: body
|
|
22
21
|
instructions: Please describe your changes.
|
|
23
22
|
type: multiline-text
|
|
24
23
|
code-sections:
|
|
25
|
-
after-string: ""
|
|
26
24
|
allow-empty: true
|
|
27
25
|
before-string: "\nCode Sections: "
|
|
28
26
|
destination: body
|
|
@@ -33,6 +31,7 @@ code-sections:
|
|
|
33
31
|
- option
|
|
34
32
|
- tests
|
|
35
33
|
- docs
|
|
34
|
+
- meta
|
|
36
35
|
record-as: joined-string
|
|
37
36
|
type: multi-select
|
|
38
37
|
ticket-number:
|
|
@@ -42,3 +41,9 @@ ticket-number:
|
|
|
42
41
|
destination: body
|
|
43
42
|
instructions: Associated Ticket Number (if any)
|
|
44
43
|
type: text
|
|
44
|
+
meta_element_changelog:
|
|
45
|
+
display_aliases:
|
|
46
|
+
fix: "fixed"
|
|
47
|
+
add: "added"
|
|
48
|
+
refactor: "refactored"
|
|
49
|
+
clean-up: "cleaned"
|
data/README.md
CHANGED
|
@@ -6,6 +6,16 @@ A simple, clean command-line option parser for Ruby.
|
|
|
6
6
|
|
|
7
7
|
Options Parser provides a straightforward way to define and parse command-line arguments in Ruby applications. It supports short and long flags, typed values, required options, and automatic help generation with colorized output.
|
|
8
8
|
|
|
9
|
+
It supports
|
|
10
|
+
|
|
11
|
+
- auto-generated help docs
|
|
12
|
+
- required & optional arguments
|
|
13
|
+
- short and/or long variations
|
|
14
|
+
- arguments that take values, or just act as flags
|
|
15
|
+
- separating flag from value with space or equals
|
|
16
|
+
- trailing arguments
|
|
17
|
+
Ex. `command -n 4 -- file_1.txt file_2.txt`
|
|
18
|
+
|
|
9
19
|
## Installation
|
|
10
20
|
|
|
11
21
|
Add to your Gemfile:
|
|
@@ -82,16 +82,31 @@ module OptionsParser
|
|
|
82
82
|
raise InvalidOptionException.new("#{arg} is not a supported option") unless current_option
|
|
83
83
|
next
|
|
84
84
|
# an argument flag when we've already encountered one
|
|
85
|
-
elsif current_option && hyphen_arg
|
|
86
|
-
#
|
|
85
|
+
elsif current_option && hyphen_arg
|
|
86
|
+
# Handle current option before switching to the new one
|
|
87
|
+
if current_option.takes_value?
|
|
88
|
+
# Option requires a value - verify it received one
|
|
89
|
+
test_satisfied_or_exit(current_option)
|
|
90
|
+
else
|
|
91
|
+
# Boolean flag - invoke it now
|
|
92
|
+
current_option.call()
|
|
93
|
+
end
|
|
94
|
+
# Switch to the new option
|
|
87
95
|
current_option = find_opt_for_arg(arg)
|
|
88
96
|
raise InvalidOptionException.new("#{arg} is not a supported option") unless current_option
|
|
89
|
-
|
|
90
|
-
elsif current_option && hyphen_arg
|
|
91
|
-
current_option.call()
|
|
92
97
|
next
|
|
93
98
|
# a separator ( no are options after this )
|
|
94
|
-
elsif separator
|
|
99
|
+
elsif separator
|
|
100
|
+
# Handle current option before processing separator
|
|
101
|
+
unless current_option.nil?
|
|
102
|
+
if current_option.takes_value?
|
|
103
|
+
# Option requires a value - verify it received one
|
|
104
|
+
test_satisfied_or_exit(current_option)
|
|
105
|
+
else
|
|
106
|
+
# Boolean flag - invoke it now
|
|
107
|
+
current_option.call()
|
|
108
|
+
end
|
|
109
|
+
end
|
|
95
110
|
separator_found = true
|
|
96
111
|
next
|
|
97
112
|
end
|
|
@@ -108,8 +123,18 @@ module OptionsParser
|
|
|
108
123
|
# if there's still an option
|
|
109
124
|
# make sure it's satisfied and call its block
|
|
110
125
|
unless current_option.nil?
|
|
111
|
-
|
|
112
|
-
|
|
126
|
+
if current_option.takes_value?
|
|
127
|
+
# Option requires a value - verify it received one
|
|
128
|
+
test_satisfied_or_exit(current_option)
|
|
129
|
+
else
|
|
130
|
+
# Boolean flag - invoke it now
|
|
131
|
+
current_option.call()
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
# Check that all required options are satisfied
|
|
135
|
+
@options.each do |opt|
|
|
136
|
+
if opt.required && !opt.satisfied?
|
|
137
|
+
test_satisfied_or_exit(opt)
|
|
113
138
|
end
|
|
114
139
|
end
|
|
115
140
|
# end parsing args
|
|
@@ -130,7 +155,7 @@ module OptionsParser
|
|
|
130
155
|
top_line_usage.push(usage_text)
|
|
131
156
|
usage_body.push(usage_text)
|
|
132
157
|
if opt.help
|
|
133
|
-
usage_body.push("\t" + help.split(/\n/).join("\n\t
|
|
158
|
+
usage_body.push("\t" + opt.help.split(/\n/).join("\n\t"))
|
|
134
159
|
end
|
|
135
160
|
end
|
|
136
161
|
puts "Usage: #{top_line_usage.join(" ")}"
|