rake_options 0.1.0 → 0.1.1
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 +12 -7
- data/lib/rake_options/template_engine.rb +8 -5
- data/lib/rake_options/version.rb +1 -1
- data/spec/integration/rake_options_integration_spec.rb +12 -12
- data/spec/rake_options/cli_parser_spec.rb +6 -6
- data/spec/rake_options/template_engine_spec.rb +6 -6
- data/spec/rake_options_spec.rb +4 -4
- 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: f139479b6f1399fc8d375f81f8b0d55c0ee617f38a029754e9ae1a70099015bb
|
4
|
+
data.tar.gz: 744d888d606e102fd3b2e442c89596ac347c8397c30004808ee4d7d6b8416464
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27a9ba60af3907fb6b346fe00f386e02ed976ec3055b330a68848e42a911183b493fdd51f4a1584df90545bdb569339b5899a2da4ffe0be94beaaba96b0a2713
|
7
|
+
data.tar.gz: 9c3f3056b9abfc8ed41e40991751c95a04c6e56d6d3cb3f4f4c76071930d4d87d5535ad4d1f9c31921acac6d12d14ed1d9ccef6d161b8a94c97f7d78b0475c1d
|
data/README.md
CHANGED
@@ -45,7 +45,12 @@ end
|
|
45
45
|
|
46
46
|
Run with:
|
47
47
|
```bash
|
48
|
-
rake build -- --with-mysql-lib
|
48
|
+
rake build -- --with-mysql-lib=/usr/local/mysql/lib --enable-feature=caching
|
49
|
+
```
|
50
|
+
|
51
|
+
For values with spaces, use quotes:
|
52
|
+
```bash
|
53
|
+
rake build -- --with-mysql-lib="/path/with spaces/lib"
|
49
54
|
```
|
50
55
|
|
51
56
|
### Bracket-Style Arguments
|
@@ -79,7 +84,7 @@ config = {
|
|
79
84
|
}
|
80
85
|
|
81
86
|
options = RakeOptions.command_line_args(config)
|
82
|
-
# Extracts both file and environment from: --config
|
87
|
+
# Extracts both file and environment from: --config=database.yml --env=production
|
83
88
|
```
|
84
89
|
|
85
90
|
### Automatic Help Documentation
|
@@ -162,8 +167,8 @@ options = RakeOptions.command_line_args(config, notation: :cli)
|
|
162
167
|
```
|
163
168
|
|
164
169
|
Supports:
|
165
|
-
- `--flag
|
166
|
-
- `--flag
|
170
|
+
- `--flag=value`
|
171
|
+
- `--flag="value with spaces"`
|
167
172
|
- Multiple flags in one command
|
168
173
|
|
169
174
|
### Bracket Notation
|
@@ -228,7 +233,7 @@ rake task -- --help
|
|
228
233
|
|
229
234
|
**Solution**: Use quotes around values with spaces:
|
230
235
|
```bash
|
231
|
-
rake task -- --path
|
236
|
+
rake task -- --path="/path/with spaces"
|
232
237
|
```
|
233
238
|
|
234
239
|
### Template not matching
|
@@ -240,8 +245,8 @@ rake task -- --path "/path/with spaces"
|
|
240
245
|
# Template
|
241
246
|
"option" => "--option $value"
|
242
247
|
|
243
|
-
# Command line must match
|
244
|
-
rake task -- --option
|
248
|
+
# Command line must match (note the = sign)
|
249
|
+
rake task -- --option=myvalue
|
245
250
|
```
|
246
251
|
|
247
252
|
## Requirements
|
@@ -57,12 +57,15 @@ module RakeOptions
|
|
57
57
|
# @return [Regexp] Regex pattern for matching
|
58
58
|
def self.build_pattern(template, variables)
|
59
59
|
# Replace $variables with capture groups that match:
|
60
|
-
# -
|
61
|
-
#
|
62
|
-
pattern_str = template.gsub(/\$\w+/, '(?:"([^"]+)"|(\S+))')
|
60
|
+
# - Values after = sign: --flag=value
|
61
|
+
# Pattern matches: --flag=value or --flag="value with spaces"
|
63
62
|
|
64
|
-
#
|
65
|
-
pattern_str =
|
63
|
+
# First, escape the template
|
64
|
+
pattern_str = Regexp.escape(template)
|
65
|
+
|
66
|
+
# Then replace escaped $variable patterns with our capture group
|
67
|
+
# The pattern after escaping looks like: \$variable
|
68
|
+
pattern_str = pattern_str.gsub(/\\ \\\$\w+/, '=(?:"([^"]+)"|([^\s]+))')
|
66
69
|
|
67
70
|
Regexp.new(pattern_str)
|
68
71
|
end
|
data/lib/rake_options/version.rb
CHANGED
@@ -13,7 +13,7 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "parses multiple CLI arguments in one invocation" do
|
16
|
-
stub_const("ARGV", ["--with-mysql-lib
|
16
|
+
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib", "--enable-feature=caching", "--port=3000"])
|
17
17
|
|
18
18
|
result = RakeOptions.command_line_args(config, notation: :cli)
|
19
19
|
|
@@ -23,7 +23,7 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "handles partial arguments gracefully" do
|
26
|
-
stub_const("ARGV", ["--with-mysql-lib
|
26
|
+
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib"])
|
27
27
|
|
28
28
|
result = RakeOptions.command_line_args(config, notation: :cli)
|
29
29
|
|
@@ -33,7 +33,7 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "supports quoted values with spaces" do
|
36
|
-
stub_const("ARGV", [
|
36
|
+
stub_const("ARGV", ['--with-mysql-lib="/path/with spaces/lib"'])
|
37
37
|
|
38
38
|
result = RakeOptions.command_line_args(config, notation: :cli)
|
39
39
|
|
@@ -41,7 +41,7 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "allows symbol key access" do
|
44
|
-
stub_const("ARGV", ["--with-mysql-lib
|
44
|
+
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib"])
|
45
45
|
|
46
46
|
result = RakeOptions.command_line_args(config, notation: :cli)
|
47
47
|
|
@@ -141,7 +141,7 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
141
141
|
end
|
142
142
|
|
143
143
|
it "handles templates with multiple variables" do
|
144
|
-
stub_const("ARGV", ["--config
|
144
|
+
stub_const("ARGV", ["--config=database.yml", "--env=production", "--verbose=debug"])
|
145
145
|
|
146
146
|
result = RakeOptions.command_line_args(config, notation: :cli)
|
147
147
|
|
@@ -161,7 +161,7 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
161
161
|
end
|
162
162
|
|
163
163
|
it "ignores unrecognized arguments" do
|
164
|
-
stub_const("ARGV", ["--unknown-flag
|
164
|
+
stub_const("ARGV", ["--unknown-flag=value", "--verbose=info"])
|
165
165
|
|
166
166
|
result = RakeOptions.command_line_args(config, notation: :cli)
|
167
167
|
|
@@ -178,14 +178,14 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
178
178
|
end
|
179
179
|
|
180
180
|
it "raises InvalidNotationError for unsupported notation" do
|
181
|
-
stub_const("ARGV", ["--option
|
181
|
+
stub_const("ARGV", ["--option=value"])
|
182
182
|
|
183
183
|
expect { RakeOptions.command_line_args(config, notation: :invalid) }
|
184
184
|
.to raise_error(RakeOptions::InvalidNotationError, /Invalid notation/)
|
185
185
|
end
|
186
186
|
|
187
187
|
it "provides clear error message with supported notations" do
|
188
|
-
stub_const("ARGV", ["--option
|
188
|
+
stub_const("ARGV", ["--option=value"])
|
189
189
|
|
190
190
|
expect { RakeOptions.command_line_args(config, notation: :xml) }
|
191
191
|
.to raise_error(RakeOptions::InvalidNotationError, /:cli, :bracket/)
|
@@ -204,7 +204,7 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
204
204
|
end
|
205
205
|
|
206
206
|
it "handles typical deployment command" do
|
207
|
-
stub_const("ARGV", ["--env
|
207
|
+
stub_const("ARGV", ["--env=production", "--region=us-east-1", "--version=v1.2.3"])
|
208
208
|
|
209
209
|
result = RakeOptions.command_line_args(deploy_config)
|
210
210
|
|
@@ -226,9 +226,9 @@ RSpec.describe "RakeOptions Integration Tests" do
|
|
226
226
|
|
227
227
|
it "handles build configuration" do
|
228
228
|
stub_const("ARGV", [
|
229
|
-
"--with-mysql-lib
|
230
|
-
"--with-ssl-lib
|
231
|
-
"--prefix
|
229
|
+
"--with-mysql-lib=/usr/local/mysql/lib",
|
230
|
+
"--with-ssl-lib=/usr/local/ssl/lib",
|
231
|
+
"--prefix=/opt/myapp"
|
232
232
|
])
|
233
233
|
|
234
234
|
result = RakeOptions.command_line_args(build_config)
|
@@ -14,7 +14,7 @@ RSpec.describe RakeOptions::CLIParser do
|
|
14
14
|
let(:parser) { described_class.new(config) }
|
15
15
|
|
16
16
|
it "parses single flag with value" do
|
17
|
-
argv = ["--with-mysql-lib
|
17
|
+
argv = ["--with-mysql-lib=/usr/local/mysql/lib"]
|
18
18
|
result = parser.parse(argv)
|
19
19
|
|
20
20
|
expect(result["with-mysql-lib"]).to eq("/usr/local/mysql/lib")
|
@@ -38,7 +38,7 @@ RSpec.describe RakeOptions::CLIParser do
|
|
38
38
|
let(:parser) { described_class.new(config) }
|
39
39
|
|
40
40
|
it "parses multiple flags in one invocation" do
|
41
|
-
argv = ["--with-mysql-lib
|
41
|
+
argv = ["--with-mysql-lib=/usr/local/lib", "--enable-feature=caching"]
|
42
42
|
result = parser.parse(argv)
|
43
43
|
|
44
44
|
expect(result["with-mysql-lib"]).to eq("/usr/local/lib")
|
@@ -46,7 +46,7 @@ RSpec.describe RakeOptions::CLIParser do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "handles partial arguments" do
|
49
|
-
argv = ["--with-mysql-lib
|
49
|
+
argv = ["--with-mysql-lib=/usr/local/lib"]
|
50
50
|
result = parser.parse(argv)
|
51
51
|
|
52
52
|
expect(result["with-mysql-lib"]).to eq("/usr/local/lib")
|
@@ -63,7 +63,7 @@ RSpec.describe RakeOptions::CLIParser do
|
|
63
63
|
let(:parser) { described_class.new(config) }
|
64
64
|
|
65
65
|
it "handles quoted values with spaces" do
|
66
|
-
argv = [
|
66
|
+
argv = ['--message="Hello World"']
|
67
67
|
result = parser.parse(argv)
|
68
68
|
|
69
69
|
expect(result["message"]).to eq("Hello World")
|
@@ -79,7 +79,7 @@ RSpec.describe RakeOptions::CLIParser do
|
|
79
79
|
let(:parser) { described_class.new(config) }
|
80
80
|
|
81
81
|
it "ignores unknown flags without raising errors" do
|
82
|
-
argv = ["--unknown-flag
|
82
|
+
argv = ["--unknown-flag=value", "--known-flag=test"]
|
83
83
|
|
84
84
|
expect { parser.parse(argv) }.not_to raise_error
|
85
85
|
result = parser.parse(argv)
|
@@ -96,7 +96,7 @@ RSpec.describe RakeOptions::CLIParser do
|
|
96
96
|
let(:parser) { described_class.new(config) }
|
97
97
|
|
98
98
|
it "extracts multiple variables" do
|
99
|
-
argv = ["--config
|
99
|
+
argv = ["--config=database.yml", "--env=production"]
|
100
100
|
result = parser.parse(argv)
|
101
101
|
|
102
102
|
expect(result["database"]).to be_a(Hash)
|
@@ -41,17 +41,17 @@ RSpec.describe RakeOptions::TemplateEngine do
|
|
41
41
|
let(:parsed_template) { described_class.parse_template("--with-mysql-lib $path") }
|
42
42
|
|
43
43
|
it "extracts value from matching input" do
|
44
|
-
input = ["--with-mysql-lib
|
44
|
+
input = ["--with-mysql-lib=/usr/local/mysql/lib"]
|
45
45
|
result = described_class.extract_values(input, parsed_template)
|
46
46
|
|
47
47
|
expect(result).to eq({ "path" => "/usr/local/mysql/lib" })
|
48
48
|
end
|
49
49
|
|
50
50
|
it "extracts quoted value with spaces" do
|
51
|
-
input = [
|
51
|
+
input = ['--with-mysql-lib="path with spaces"']
|
52
52
|
result = described_class.extract_values(input, parsed_template)
|
53
53
|
|
54
|
-
expect(result["path"]).to
|
54
|
+
expect(result["path"]).to eq("path with spaces")
|
55
55
|
end
|
56
56
|
|
57
57
|
it "returns nil for non-matching input" do
|
@@ -66,7 +66,7 @@ RSpec.describe RakeOptions::TemplateEngine do
|
|
66
66
|
let(:parsed_template) { described_class.parse_template("--config $file --env $environment") }
|
67
67
|
|
68
68
|
it "extracts multiple values from matching input" do
|
69
|
-
input = ["--config
|
69
|
+
input = ["--config=database.yml", "--env=production"]
|
70
70
|
result = described_class.extract_values(input, parsed_template)
|
71
71
|
|
72
72
|
expect(result["file"]).to eq("database.yml")
|
@@ -98,7 +98,7 @@ RSpec.describe RakeOptions::TemplateEngine do
|
|
98
98
|
pattern = described_class.send(:build_pattern, "--with-mysql-lib $path", variables)
|
99
99
|
|
100
100
|
expect(pattern).to be_a(Regexp)
|
101
|
-
expect("--with-mysql-lib
|
101
|
+
expect("--with-mysql-lib=/usr/local/lib").to match(pattern)
|
102
102
|
end
|
103
103
|
|
104
104
|
it "creates pattern for multiple variables" do
|
@@ -106,7 +106,7 @@ RSpec.describe RakeOptions::TemplateEngine do
|
|
106
106
|
pattern = described_class.send(:build_pattern, "--config $file --env $env", variables)
|
107
107
|
|
108
108
|
expect(pattern).to be_a(Regexp)
|
109
|
-
expect("--config
|
109
|
+
expect("--config=db.yml --env=prod").to match(pattern)
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
data/spec/rake_options_spec.rb
CHANGED
@@ -13,14 +13,14 @@ RSpec.describe RakeOptions do
|
|
13
13
|
describe ".command_line_args" do
|
14
14
|
context "with CLI notation" do
|
15
15
|
it "parses CLI-style arguments" do
|
16
|
-
stub_const("ARGV", ["--with-mysql-lib
|
16
|
+
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib"])
|
17
17
|
result = described_class.command_line_args(config, notation: :cli)
|
18
18
|
|
19
19
|
expect(result["with-mysql-lib"]).to eq("/usr/local/lib")
|
20
20
|
end
|
21
21
|
|
22
22
|
it "supports symbol key access" do
|
23
|
-
stub_const("ARGV", ["--with-mysql-lib
|
23
|
+
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib"])
|
24
24
|
result = described_class.command_line_args(config, notation: :cli)
|
25
25
|
|
26
26
|
expect(result[:with_mysql_lib]).to eq("/usr/local/lib")
|
@@ -38,7 +38,7 @@ RSpec.describe RakeOptions do
|
|
38
38
|
|
39
39
|
context "with default notation" do
|
40
40
|
it "defaults to CLI notation" do
|
41
|
-
stub_const("ARGV", ["--with-mysql-lib
|
41
|
+
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib"])
|
42
42
|
result = described_class.command_line_args(config)
|
43
43
|
|
44
44
|
expect(result["with-mysql-lib"]).to eq("/usr/local/lib")
|
@@ -57,7 +57,7 @@ RSpec.describe RakeOptions do
|
|
57
57
|
|
58
58
|
context "return value" do
|
59
59
|
it "returns HashWithIndifferentAccess" do
|
60
|
-
stub_const("ARGV", ["--with-mysql-lib
|
60
|
+
stub_const("ARGV", ["--with-mysql-lib=/usr/local/lib"])
|
61
61
|
result = described_class.command_line_args(config)
|
62
62
|
|
63
63
|
expect(result).to be_a(RakeOptions::HashWithIndifferentAccess)
|