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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 407b2f4ed706b0be1a0e8b4ce7397d82c0152137eda948d03cf191c03d803f11
4
- data.tar.gz: bf06e068a8d04793a9d181b49ef6e0826c9ff7b8a6d099429078f7c9b4cc99e2
3
+ metadata.gz: 46f025bfa171807935c0c1c48163f76546bd01a0609ed9f6646a741e2927e8df
4
+ data.tar.gz: 55b6e9162403c49b91b42aa432599cedee4a431a220228d504c16d1d5dac961c
5
5
  SHA512:
6
- metadata.gz: 53b83b4c5633c789554566cfd810a54aade3f7d9ee501caec333cdbd93f1cb70be2e90a57dd5e5e057d9f248de3abd99cefe9009ad3bfba79b8772126de7ca34
7
- data.tar.gz: 9cd7b5ec11c783b2f9b035df6449f2ab910c88ac78e2239448bd37180ac9512de66617245fe1ec81eb360bd0097406d14cbd0ce4b0e7efd5b61a1830c13137c1
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:
@@ -12,7 +12,7 @@ module OptionsParser
12
12
  @short = short
13
13
  @long = long
14
14
  @help = help
15
- @required = false if required.nil?
15
+ @required = required || false
16
16
  @value = nil
17
17
  raise "Option must contain a short or long flag" if @short.nil? && @long.nil?
18
18
  end
@@ -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 && test_satisfied_or_exit(current_option)
86
- # execute the option's block
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 && (current_option.nil? || test_satisfied_or_exit(current_option))
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
- unless test_satisfied_or_exit(current_option)
112
- current_option.call()
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\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(" ")}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OptionsParser
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: options_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - masukomi