rake_options 0.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.
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "rake_options/template_engine"
5
+
6
+ RSpec.describe RakeOptions::TemplateEngine do
7
+ describe ".parse_template" do
8
+ context "with single variable" do
9
+ it "parses template with one variable" do
10
+ result = described_class.parse_template("--with-mysql-lib $path")
11
+
12
+ expect(result[:template]).to eq("--with-mysql-lib $path")
13
+ expect(result[:variables]).to eq(["path"])
14
+ expect(result[:pattern]).to be_a(Regexp)
15
+ end
16
+ end
17
+
18
+ context "with multiple variables" do
19
+ it "parses template with multiple variables" do
20
+ result = described_class.parse_template("--config $file --env $environment")
21
+
22
+ expect(result[:template]).to eq("--config $file --env $environment")
23
+ expect(result[:variables]).to eq(["file", "environment"])
24
+ expect(result[:pattern]).to be_a(Regexp)
25
+ end
26
+ end
27
+
28
+ context "with no variables" do
29
+ it "parses template without variables" do
30
+ result = described_class.parse_template("--enable-feature")
31
+
32
+ expect(result[:template]).to eq("--enable-feature")
33
+ expect(result[:variables]).to eq([])
34
+ expect(result[:pattern]).to be_a(Regexp)
35
+ end
36
+ end
37
+ end
38
+
39
+ describe ".extract_values" do
40
+ context "with single variable template" do
41
+ let(:parsed_template) { described_class.parse_template("--with-mysql-lib $path") }
42
+
43
+ it "extracts value from matching input" do
44
+ input = ["--with-mysql-lib", "/usr/local/mysql/lib"]
45
+ result = described_class.extract_values(input, parsed_template)
46
+
47
+ expect(result).to eq({ "path" => "/usr/local/mysql/lib" })
48
+ end
49
+
50
+ it "extracts quoted value with spaces" do
51
+ input = ["--with-mysql-lib", '"path with spaces"']
52
+ result = described_class.extract_values(input, parsed_template)
53
+
54
+ expect(result["path"]).to include("path")
55
+ end
56
+
57
+ it "returns nil for non-matching input" do
58
+ input = ["--different-flag", "value"]
59
+ result = described_class.extract_values(input, parsed_template)
60
+
61
+ expect(result).to be_nil
62
+ end
63
+ end
64
+
65
+ context "with multiple variable template" do
66
+ let(:parsed_template) { described_class.parse_template("--config $file --env $environment") }
67
+
68
+ it "extracts multiple values from matching input" do
69
+ input = ["--config", "database.yml", "--env", "production"]
70
+ result = described_class.extract_values(input, parsed_template)
71
+
72
+ expect(result["file"]).to eq("database.yml")
73
+ expect(result["environment"]).to eq("production")
74
+ end
75
+ end
76
+ end
77
+
78
+ describe ".identify_variables" do
79
+ it "finds single variable" do
80
+ variables = described_class.send(:identify_variables, "--flag $var")
81
+ expect(variables).to eq(["var"])
82
+ end
83
+
84
+ it "finds multiple variables" do
85
+ variables = described_class.send(:identify_variables, "--flag $var1 --other $var2")
86
+ expect(variables).to eq(["var1", "var2"])
87
+ end
88
+
89
+ it "returns empty array when no variables" do
90
+ variables = described_class.send(:identify_variables, "--flag value")
91
+ expect(variables).to eq([])
92
+ end
93
+ end
94
+
95
+ describe ".build_pattern" do
96
+ it "creates pattern for single variable" do
97
+ variables = ["path"]
98
+ pattern = described_class.send(:build_pattern, "--with-mysql-lib $path", variables)
99
+
100
+ expect(pattern).to be_a(Regexp)
101
+ expect("--with-mysql-lib /usr/local/lib").to match(pattern)
102
+ end
103
+
104
+ it "creates pattern for multiple variables" do
105
+ variables = ["file", "env"]
106
+ pattern = described_class.send(:build_pattern, "--config $file --env $env", variables)
107
+
108
+ expect(pattern).to be_a(Regexp)
109
+ expect("--config db.yml --env prod").to match(pattern)
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe RakeOptions do
6
+ let(:config) do
7
+ {
8
+ "with-mysql-lib" => "--with-mysql-lib $path",
9
+ "enable-feature" => "--enable-feature $name"
10
+ }
11
+ end
12
+
13
+ describe ".command_line_args" do
14
+ context "with CLI notation" do
15
+ it "parses CLI-style arguments" do
16
+ stub_const("ARGV", ["--with-mysql-lib", "/usr/local/lib"])
17
+ result = described_class.command_line_args(config, notation: :cli)
18
+
19
+ expect(result["with-mysql-lib"]).to eq("/usr/local/lib")
20
+ end
21
+
22
+ it "supports symbol key access" do
23
+ stub_const("ARGV", ["--with-mysql-lib", "/usr/local/lib"])
24
+ result = described_class.command_line_args(config, notation: :cli)
25
+
26
+ expect(result[:with_mysql_lib]).to eq("/usr/local/lib")
27
+ end
28
+ end
29
+
30
+ context "with bracket notation" do
31
+ it "parses bracket-style arguments" do
32
+ stub_const("ARGV", ["[with-mysql-lib=/usr/local/lib]"])
33
+ result = described_class.command_line_args(config, notation: :bracket)
34
+
35
+ expect(result["with-mysql-lib"]).to eq("/usr/local/lib")
36
+ end
37
+ end
38
+
39
+ context "with default notation" do
40
+ it "defaults to CLI notation" do
41
+ stub_const("ARGV", ["--with-mysql-lib", "/usr/local/lib"])
42
+ result = described_class.command_line_args(config)
43
+
44
+ expect(result["with-mysql-lib"]).to eq("/usr/local/lib")
45
+ end
46
+ end
47
+
48
+ context "with --help flag" do
49
+ it "triggers help display and exits" do
50
+ stub_const("ARGV", ["--help"])
51
+
52
+ expect { described_class.command_line_args(config) }
53
+ .to output(/Available Options/).to_stdout
54
+ .and raise_error(SystemExit)
55
+ end
56
+ end
57
+
58
+ context "return value" do
59
+ it "returns HashWithIndifferentAccess" do
60
+ stub_const("ARGV", ["--with-mysql-lib", "/usr/local/lib"])
61
+ result = described_class.command_line_args(config)
62
+
63
+ expect(result).to be_a(RakeOptions::HashWithIndifferentAccess)
64
+ end
65
+ end
66
+ end
67
+
68
+ describe ".initialize_readme" do
69
+ it "stores readme content" do
70
+ readme = "Custom help text"
71
+ described_class.initialize_readme(readme)
72
+
73
+ expect(described_class.readme_content).to eq(readme)
74
+ end
75
+
76
+ it "uses stored readme in help display" do
77
+ readme = "My Custom Help"
78
+ described_class.initialize_readme(readme)
79
+ stub_const("ARGV", ["--help"])
80
+
81
+ expect { described_class.command_line_args(config) }
82
+ .to output(/My Custom Help/).to_stdout
83
+ .and raise_error(SystemExit)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake_options"
4
+
5
+ RSpec.configure do |config|
6
+ # Enable flags like --only-failures and --next-failure
7
+ config.example_status_persistence_file_path = ".rspec_status"
8
+
9
+ # Disable RSpec exposing methods globally on `Module` and `main`
10
+ config.disable_monkey_patching!
11
+
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = :expect
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake_options
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Randy Villanueva
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ description: RakeOptions provides an intuitive API for parsing command line arguments
42
+ in rake tasks with support for multiple notation styles and automatic help documentation
43
+ generation.
44
+ email:
45
+ - randyv128@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - lib/rake_options.rb
54
+ - lib/rake_options/argument_parser.rb
55
+ - lib/rake_options/bracket_parser.rb
56
+ - lib/rake_options/cli_parser.rb
57
+ - lib/rake_options/errors.rb
58
+ - lib/rake_options/hash_with_indifferent_access.rb
59
+ - lib/rake_options/help_generator.rb
60
+ - lib/rake_options/template_engine.rb
61
+ - lib/rake_options/version.rb
62
+ - spec/integration/rake_options_integration_spec.rb
63
+ - spec/rake_options/argument_parser_spec.rb
64
+ - spec/rake_options/bracket_parser_spec.rb
65
+ - spec/rake_options/cli_parser_spec.rb
66
+ - spec/rake_options/help_generator_spec.rb
67
+ - spec/rake_options/template_engine_spec.rb
68
+ - spec/rake_options_spec.rb
69
+ - spec/spec_helper.rb
70
+ homepage: https://github.com/randyv128/rake_options
71
+ licenses:
72
+ - MIT
73
+ metadata:
74
+ homepage_uri: https://github.com/randyv128/rake_options
75
+ source_code_uri: https://github.com/randyv128/rake_options
76
+ changelog_uri: https://github.com/randyv128/rake_options/blob/main/CHANGELOG.md
77
+ allowed_push_host: https://rubygems.org
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 2.7.0
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.4.10
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Simplify command line argument handling for rake tasks
97
+ test_files: []