rake_options 0.1.2 → 0.1.3
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/README.md +3 -35
- data/lib/rake_options/version.rb +1 -1
- data/lib/rake_options.rb +5 -6
- data/spec/integration/rake_options_integration_spec.rb +7 -62
- data/spec/rake_options_spec.rb +6 -16
- metadata +2 -6
- data/lib/rake_options/argument_parser.rb +0 -46
- data/lib/rake_options/bracket_parser.rb +0 -64
- data/spec/rake_options/argument_parser_spec.rb +0 -71
- data/spec/rake_options/bracket_parser_spec.rb +0 -86
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c23f2f501224d1849ee5255aafb6f023e12f6bacdeacdcd2a4909eb711e73adb
|
4
|
+
data.tar.gz: eaaa2f161b92704669317004e64dfee3267f4473095a561be9b8c71354d6362e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b507cb81d6ae6518115b35ce028779d7dbccbdebac5d328970ff2935269cf4d46041bc45927333d39efe897ede7646087873401095295635853e0d6e1a542560
|
7
|
+
data.tar.gz: 54a8901e28628730a2a15c8a2b53a06a89bdc0e1c621aa437dcef36890f4ee6f8c7cff07c32b3d299a6ce42360137661266426d1323995caa001fdd17052a67a
|
data/README.md
CHANGED
@@ -83,28 +83,7 @@ Supported types:
|
|
83
83
|
- `:float` - Float values
|
84
84
|
- `:boolean` or `:bool` - Boolean values (true/false)
|
85
85
|
|
86
|
-
### Bracket-Style Arguments
|
87
86
|
|
88
|
-
```ruby
|
89
|
-
require 'rake_options'
|
90
|
-
|
91
|
-
desc "Deploy with bracket notation"
|
92
|
-
task :deploy do
|
93
|
-
config = [
|
94
|
-
["environment", :string],
|
95
|
-
["region", :string]
|
96
|
-
]
|
97
|
-
|
98
|
-
options = RakeOptions.command_line_args(config, notation: :bracket)
|
99
|
-
|
100
|
-
puts "Deploying to #{options['environment']} in #{options['region']}"
|
101
|
-
end
|
102
|
-
```
|
103
|
-
|
104
|
-
Run with:
|
105
|
-
```bash
|
106
|
-
rake deploy [environment=production] [region=us-west-2]
|
107
|
-
```
|
108
87
|
|
109
88
|
### Automatic Help Documentation
|
110
89
|
|
@@ -182,12 +161,12 @@ The configuration is a simple array of tuples:
|
|
182
161
|
["ratio", :float]
|
183
162
|
```
|
184
163
|
|
185
|
-
##
|
164
|
+
## Usage Format
|
186
165
|
|
187
|
-
|
166
|
+
RakeOptions uses standard CLI flag format:
|
188
167
|
|
189
168
|
```ruby
|
190
|
-
options = RakeOptions.command_line_args(config
|
169
|
+
options = RakeOptions.command_line_args(config)
|
191
170
|
```
|
192
171
|
|
193
172
|
Supports:
|
@@ -195,17 +174,6 @@ Supports:
|
|
195
174
|
- `--flag="value with spaces"`
|
196
175
|
- Multiple flags in one command
|
197
176
|
|
198
|
-
### Bracket Notation
|
199
|
-
|
200
|
-
```ruby
|
201
|
-
options = RakeOptions.command_line_args(config, notation: :bracket)
|
202
|
-
```
|
203
|
-
|
204
|
-
Supports:
|
205
|
-
- `[key=value]`
|
206
|
-
- `[key="value with spaces"]`
|
207
|
-
- Multiple bracket arguments
|
208
|
-
|
209
177
|
## Error Handling
|
210
178
|
|
211
179
|
RakeOptions provides clear error messages:
|
data/lib/rake_options/version.rb
CHANGED
data/lib/rake_options.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative "rake_options/version"
|
4
4
|
require_relative "rake_options/errors"
|
5
|
-
require_relative "rake_options/
|
5
|
+
require_relative "rake_options/cli_parser"
|
6
6
|
require_relative "rake_options/help_generator"
|
7
7
|
require_relative "rake_options/hash_with_indifferent_access"
|
8
8
|
|
@@ -11,18 +11,17 @@ module RakeOptions
|
|
11
11
|
attr_accessor :readme_content
|
12
12
|
|
13
13
|
# Parse command line arguments based on configuration
|
14
|
-
# @param config [
|
15
|
-
# @param notation [Symbol] Notation style (:cli or :bracket)
|
14
|
+
# @param config [Array] Argument configuration as array of [name, type] tuples
|
16
15
|
# @return [HashWithIndifferentAccess] Parsed arguments with indifferent access
|
17
|
-
def command_line_args(config
|
16
|
+
def command_line_args(config)
|
18
17
|
# Check for --help flag
|
19
18
|
if ARGV.include?("--help")
|
20
19
|
help_generator = HelpGenerator.new(config, readme_content)
|
21
20
|
help_generator.display_and_exit
|
22
21
|
end
|
23
22
|
|
24
|
-
# Parse arguments
|
25
|
-
parser =
|
23
|
+
# Parse arguments using CLI parser
|
24
|
+
parser = CLIParser.new(config)
|
26
25
|
result = parser.parse
|
27
26
|
|
28
27
|
# Wrap in HashWithIndifferentAccess
|
@@ -15,7 +15,7 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
15
15
|
it "parses multiple CLI arguments in one invocation" do
|
16
16
|
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib", "--enable-feature=caching", "--port=3000"])
|
17
17
|
|
18
|
-
result = RakeOptions.command_line_args(config
|
18
|
+
result = RakeOptions.command_line_args(config)
|
19
19
|
|
20
20
|
expect(result["with-mysql-lib"]).to eq("/usr/local/lib")
|
21
21
|
expect(result["enable-feature"]).to eq("caching")
|
@@ -25,7 +25,7 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
25
25
|
it "handles partial arguments gracefully" do
|
26
26
|
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib"])
|
27
27
|
|
28
|
-
result = RakeOptions.command_line_args(config
|
28
|
+
result = RakeOptions.command_line_args(config)
|
29
29
|
|
30
30
|
expect(result["with-mysql-lib"]).to eq("/usr/local/lib")
|
31
31
|
expect(result["enable-feature"]).to be_nil
|
@@ -35,7 +35,7 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
35
35
|
it "supports quoted values with spaces" do
|
36
36
|
stub_const("ARGV", ['--with-mysql-lib="/path/with spaces/lib"'])
|
37
37
|
|
38
|
-
result = RakeOptions.command_line_args(config
|
38
|
+
result = RakeOptions.command_line_args(config)
|
39
39
|
|
40
40
|
expect(result["with-mysql-lib"]).to eq("/path/with spaces/lib")
|
41
41
|
end
|
@@ -43,50 +43,13 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
43
43
|
it "allows symbol key access" do
|
44
44
|
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib"])
|
45
45
|
|
46
|
-
result = RakeOptions.command_line_args(config
|
46
|
+
result = RakeOptions.command_line_args(config)
|
47
47
|
|
48
48
|
expect(result[:with_mysql_lib]).to eq("/usr/local/lib")
|
49
49
|
expect(result["with-mysql-lib"]).to eq("/usr/local/lib")
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
describe "Full bracket parsing workflow" do
|
54
|
-
let(:config) do
|
55
|
-
{
|
56
|
-
"environment" => "[environment=$env]",
|
57
|
-
"region" => "[region=$reg]",
|
58
|
-
"instance-type" => "[instance-type=$type]"
|
59
|
-
}
|
60
|
-
end
|
61
|
-
|
62
|
-
it "parses multiple bracket arguments" do
|
63
|
-
stub_const("ARGV", ["[environment=production]", "[region=us-west-2]", "[instance-type=t2.micro]"])
|
64
|
-
|
65
|
-
result = RakeOptions.command_line_args(config, notation: :bracket)
|
66
|
-
|
67
|
-
expect(result["environment"]).to eq("production")
|
68
|
-
expect(result["region"]).to eq("us-west-2")
|
69
|
-
expect(result["instance-type"]).to eq("t2.micro")
|
70
|
-
end
|
71
|
-
|
72
|
-
it "handles quoted bracket values" do
|
73
|
-
stub_const("ARGV", ['[environment="staging environment"]'])
|
74
|
-
|
75
|
-
result = RakeOptions.command_line_args(config, notation: :bracket)
|
76
|
-
|
77
|
-
expect(result["environment"]).to eq("staging environment")
|
78
|
-
end
|
79
|
-
|
80
|
-
it "supports symbol key access with dashes/underscores" do
|
81
|
-
stub_const("ARGV", ["[instance-type=t2.micro]"])
|
82
|
-
|
83
|
-
result = RakeOptions.command_line_args(config, notation: :bracket)
|
84
|
-
|
85
|
-
expect(result[:instance_type]).to eq("t2.micro")
|
86
|
-
expect(result["instance-type"]).to eq("t2.micro")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
53
|
describe "Help display integration" do
|
91
54
|
let(:config) do
|
92
55
|
{
|
@@ -143,7 +106,7 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
143
106
|
it "handles multiple arguments" do
|
144
107
|
stub_const("ARGV", ["--database=mydb", "--verbose=debug"])
|
145
108
|
|
146
|
-
result = RakeOptions.command_line_args(config
|
109
|
+
result = RakeOptions.command_line_args(config)
|
147
110
|
|
148
111
|
expect(result["database"]).to eq("mydb")
|
149
112
|
expect(result["verbose"]).to eq("debug")
|
@@ -152,7 +115,7 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
152
115
|
it "handles empty ARGV" do
|
153
116
|
stub_const("ARGV", [])
|
154
117
|
|
155
|
-
result = RakeOptions.command_line_args(config
|
118
|
+
result = RakeOptions.command_line_args(config)
|
156
119
|
|
157
120
|
expect(result["database"]).to be_nil
|
158
121
|
expect(result["verbose"]).to be_nil
|
@@ -161,32 +124,14 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
161
124
|
it "ignores unrecognized arguments" do
|
162
125
|
stub_const("ARGV", ["--unknown-flag=value", "--verbose=info"])
|
163
126
|
|
164
|
-
result = RakeOptions.command_line_args(config
|
127
|
+
result = RakeOptions.command_line_args(config)
|
165
128
|
|
166
129
|
expect(result["verbose"]).to eq("info")
|
167
130
|
expect(result["database"]).to be_nil
|
168
131
|
end
|
169
132
|
end
|
170
133
|
|
171
|
-
describe "Error scenarios" do
|
172
|
-
let(:config) do
|
173
|
-
[["option", :string]]
|
174
|
-
end
|
175
134
|
|
176
|
-
it "raises InvalidNotationError for unsupported notation" do
|
177
|
-
stub_const("ARGV", ["--option=value"])
|
178
|
-
|
179
|
-
expect { RakeOptions.command_line_args(config, notation: :invalid) }
|
180
|
-
.to raise_error(RakeOptions::InvalidNotationError, /Invalid notation/)
|
181
|
-
end
|
182
|
-
|
183
|
-
it "provides clear error message with supported notations" do
|
184
|
-
stub_const("ARGV", ["--option=value"])
|
185
|
-
|
186
|
-
expect { RakeOptions.command_line_args(config, notation: :xml) }
|
187
|
-
.to raise_error(RakeOptions::InvalidNotationError, /:cli, :bracket/)
|
188
|
-
end
|
189
|
-
end
|
190
135
|
|
191
136
|
describe "Real-world usage scenarios" do
|
192
137
|
context "deployment task" do
|
data/spec/rake_options_spec.rb
CHANGED
@@ -8,37 +8,27 @@ RSpec.describe RakeOptions do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe ".command_line_args" do
|
11
|
-
context "
|
11
|
+
context "parsing arguments" do
|
12
12
|
it "parses CLI-style arguments" do
|
13
13
|
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib"])
|
14
|
-
result = described_class.command_line_args(config
|
14
|
+
result = described_class.command_line_args(config)
|
15
15
|
|
16
16
|
expect(result["with-mysql-lib"]).to eq("/usr/local/lib")
|
17
17
|
end
|
18
18
|
|
19
19
|
it "supports symbol key access" do
|
20
20
|
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib"])
|
21
|
-
result = described_class.command_line_args(config
|
21
|
+
result = described_class.command_line_args(config)
|
22
22
|
|
23
23
|
expect(result[:with_mysql_lib]).to eq("/usr/local/lib")
|
24
24
|
end
|
25
|
-
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
stub_const("ARGV", ["[with-mysql-lib=/usr/local/lib]"])
|
30
|
-
result = described_class.command_line_args(config, notation: :bracket)
|
31
|
-
|
32
|
-
expect(result["with-mysql-lib"]).to eq("/usr/local/lib")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "with default notation" do
|
37
|
-
it "defaults to CLI notation" do
|
38
|
-
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib"])
|
26
|
+
it "parses multiple arguments" do
|
27
|
+
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib", "--enable-feature=caching"])
|
39
28
|
result = described_class.command_line_args(config)
|
40
29
|
|
41
30
|
expect(result["with-mysql-lib"]).to eq("/usr/local/lib")
|
31
|
+
expect(result["enable-feature"]).to eq("caching")
|
42
32
|
end
|
43
33
|
end
|
44
34
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake_options
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Randy Villanueva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-10-
|
11
|
+
date: 2025-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -51,8 +51,6 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- lib/rake_options.rb
|
54
|
-
- lib/rake_options/argument_parser.rb
|
55
|
-
- lib/rake_options/bracket_parser.rb
|
56
54
|
- lib/rake_options/cli_parser.rb
|
57
55
|
- lib/rake_options/errors.rb
|
58
56
|
- lib/rake_options/hash_with_indifferent_access.rb
|
@@ -60,8 +58,6 @@ files:
|
|
60
58
|
- lib/rake_options/template_engine.rb
|
61
59
|
- lib/rake_options/version.rb
|
62
60
|
- spec/integration/rake_options_integration_spec.rb
|
63
|
-
- spec/rake_options/argument_parser_spec.rb
|
64
|
-
- spec/rake_options/bracket_parser_spec.rb
|
65
61
|
- spec/rake_options/cli_parser_spec.rb
|
66
62
|
- spec/rake_options/help_generator_spec.rb
|
67
63
|
- spec/rake_options/template_engine_spec.rb
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "cli_parser"
|
4
|
-
require_relative "bracket_parser"
|
5
|
-
require_relative "errors"
|
6
|
-
|
7
|
-
module RakeOptions
|
8
|
-
class ArgumentParser
|
9
|
-
VALID_NOTATIONS = [:cli, :bracket].freeze
|
10
|
-
|
11
|
-
def initialize(config, notation)
|
12
|
-
@config = config
|
13
|
-
@notation = notation
|
14
|
-
validate_notation
|
15
|
-
end
|
16
|
-
|
17
|
-
# Parse ARGV and return structured options
|
18
|
-
# @return [Hash] Parsed options
|
19
|
-
def parse
|
20
|
-
parser = select_parser
|
21
|
-
parser.parse
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
# Select appropriate parser based on notation
|
27
|
-
# @return [CLIParser, BracketParser] Parser instance
|
28
|
-
def select_parser
|
29
|
-
case @notation
|
30
|
-
when :cli
|
31
|
-
CLIParser.new(@config)
|
32
|
-
when :bracket
|
33
|
-
BracketParser.new(@config)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Validate notation parameter
|
38
|
-
# @raise [InvalidNotationError] if notation is invalid
|
39
|
-
def validate_notation
|
40
|
-
return if VALID_NOTATIONS.include?(@notation)
|
41
|
-
|
42
|
-
raise InvalidNotationError,
|
43
|
-
"Invalid notation ':#{@notation}'. Supported notations: #{VALID_NOTATIONS.map { |n| ":#{n}" }.join(', ')}"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RakeOptions
|
4
|
-
class BracketParser
|
5
|
-
def initialize(config)
|
6
|
-
@config = config
|
7
|
-
end
|
8
|
-
|
9
|
-
# Parse bracket-style arguments from ARGV
|
10
|
-
# @param argv [Array] Command line arguments (defaults to ARGV)
|
11
|
-
# @return [Hash] Parsed values
|
12
|
-
def parse(argv = ARGV)
|
13
|
-
result = {}
|
14
|
-
|
15
|
-
# Extract all bracket arguments from argv
|
16
|
-
bracket_args = extract_bracket_args(argv)
|
17
|
-
|
18
|
-
# Match bracket args to config keys
|
19
|
-
@config.each do |key, _template|
|
20
|
-
# Look for matching bracket key
|
21
|
-
if bracket_args.key?(key)
|
22
|
-
result[key] = bracket_args[key]
|
23
|
-
else
|
24
|
-
result[key] = nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
result
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
# Find all [key=value] patterns in argv
|
34
|
-
# @param argv [Array] Command line arguments
|
35
|
-
# @return [Hash] Extracted key-value pairs
|
36
|
-
def extract_bracket_args(argv)
|
37
|
-
result = {}
|
38
|
-
|
39
|
-
argv.each do |arg|
|
40
|
-
# Match [key=value] or [key="value"]
|
41
|
-
match = arg.match(/^\[([^=]+)=(.+)\]$/)
|
42
|
-
next unless match
|
43
|
-
|
44
|
-
key = match[1]
|
45
|
-
value = parse_bracket_value(match[2])
|
46
|
-
result[key] = value
|
47
|
-
end
|
48
|
-
|
49
|
-
result
|
50
|
-
end
|
51
|
-
|
52
|
-
# Handle quoted and unquoted values in brackets
|
53
|
-
# @param value [String] Value from bracket
|
54
|
-
# @return [String] Parsed value
|
55
|
-
def parse_bracket_value(value)
|
56
|
-
# Remove surrounding quotes if present
|
57
|
-
if value.start_with?('"') && value.end_with?('"')
|
58
|
-
value[1..-2]
|
59
|
-
else
|
60
|
-
value
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
require "rake_options/argument_parser"
|
5
|
-
|
6
|
-
RSpec.describe RakeOptions::ArgumentParser do
|
7
|
-
let(:config) do
|
8
|
-
{
|
9
|
-
"option1" => "--option1 $value"
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#initialize" do
|
14
|
-
context "with valid notation" do
|
15
|
-
it "accepts :cli notation" do
|
16
|
-
expect { described_class.new(config, :cli) }.not_to raise_error
|
17
|
-
end
|
18
|
-
|
19
|
-
it "accepts :bracket notation" do
|
20
|
-
expect { described_class.new(config, :bracket) }.not_to raise_error
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "with invalid notation" do
|
25
|
-
it "raises InvalidNotationError" do
|
26
|
-
expect { described_class.new(config, :invalid) }.to raise_error(RakeOptions::InvalidNotationError)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "provides helpful error message" do
|
30
|
-
expect { described_class.new(config, :invalid) }.to raise_error(
|
31
|
-
RakeOptions::InvalidNotationError,
|
32
|
-
/Invalid notation ':invalid'. Supported notations: :cli, :bracket/
|
33
|
-
)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#parse" do
|
39
|
-
context "with CLI notation" do
|
40
|
-
let(:parser) { described_class.new(config, :cli) }
|
41
|
-
|
42
|
-
it "uses CLIParser" do
|
43
|
-
expect(RakeOptions::CLIParser).to receive(:new).with(config).and_call_original
|
44
|
-
parser.parse
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "with bracket notation" do
|
49
|
-
let(:parser) { described_class.new(config, :bracket) }
|
50
|
-
|
51
|
-
it "uses BracketParser" do
|
52
|
-
expect(RakeOptions::BracketParser).to receive(:new).with(config).and_call_original
|
53
|
-
parser.parse
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "#select_parser" do
|
59
|
-
it "returns CLIParser for :cli notation" do
|
60
|
-
parser = described_class.new(config, :cli)
|
61
|
-
selected = parser.send(:select_parser)
|
62
|
-
expect(selected).to be_a(RakeOptions::CLIParser)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "returns BracketParser for :bracket notation" do
|
66
|
-
parser = described_class.new(config, :bracket)
|
67
|
-
selected = parser.send(:select_parser)
|
68
|
-
expect(selected).to be_a(RakeOptions::BracketParser)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
require "rake_options/bracket_parser"
|
5
|
-
|
6
|
-
RSpec.describe RakeOptions::BracketParser do
|
7
|
-
describe "#parse" do
|
8
|
-
context "with simple key=value" do
|
9
|
-
let(:config) do
|
10
|
-
{
|
11
|
-
"environment" => "[environment=$env]",
|
12
|
-
"region" => "[region=$region]"
|
13
|
-
}
|
14
|
-
end
|
15
|
-
let(:parser) { described_class.new(config) }
|
16
|
-
|
17
|
-
it "parses [key=value] format" do
|
18
|
-
argv = ["[environment=production]", "[region=us-west-2]"]
|
19
|
-
result = parser.parse(argv)
|
20
|
-
|
21
|
-
expect(result["environment"]).to eq("production")
|
22
|
-
expect(result["region"]).to eq("us-west-2")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns nil for missing arguments" do
|
26
|
-
argv = ["[environment=production]"]
|
27
|
-
result = parser.parse(argv)
|
28
|
-
|
29
|
-
expect(result["environment"]).to eq("production")
|
30
|
-
expect(result["region"]).to be_nil
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "with quoted values" do
|
35
|
-
let(:config) do
|
36
|
-
{
|
37
|
-
"message" => "[message=$text]"
|
38
|
-
}
|
39
|
-
end
|
40
|
-
let(:parser) { described_class.new(config) }
|
41
|
-
|
42
|
-
it "parses [key=\"value with spaces\"] format" do
|
43
|
-
argv = ['[message="Hello World"]']
|
44
|
-
result = parser.parse(argv)
|
45
|
-
|
46
|
-
expect(result["message"]).to eq("Hello World")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "with multiple bracket arguments" do
|
51
|
-
let(:config) do
|
52
|
-
{
|
53
|
-
"env" => "[env=$environment]",
|
54
|
-
"region" => "[region=$reg]",
|
55
|
-
"instance" => "[instance=$type]"
|
56
|
-
}
|
57
|
-
end
|
58
|
-
let(:parser) { described_class.new(config) }
|
59
|
-
|
60
|
-
it "parses multiple bracket arguments" do
|
61
|
-
argv = ["[env=prod]", "[region=us-east-1]", "[instance=t2.micro]"]
|
62
|
-
result = parser.parse(argv)
|
63
|
-
|
64
|
-
expect(result["env"]).to eq("prod")
|
65
|
-
expect(result["region"]).to eq("us-east-1")
|
66
|
-
expect(result["instance"]).to eq("t2.micro")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "with malformed brackets" do
|
71
|
-
let(:config) do
|
72
|
-
{
|
73
|
-
"valid" => "[valid=$val]"
|
74
|
-
}
|
75
|
-
end
|
76
|
-
let(:parser) { described_class.new(config) }
|
77
|
-
|
78
|
-
it "ignores malformed bracket arguments" do
|
79
|
-
argv = ["[valid=test]", "invalid=value", "[missing-bracket"]
|
80
|
-
result = parser.parse(argv)
|
81
|
-
|
82
|
-
expect(result["valid"]).to eq("test")
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|