Class: Ace::TestRunner::Molecules::CliArgumentParser
- Inherits:
-
Object
- Object
- Ace::TestRunner::Molecules::CliArgumentParser
- Defined in:
- lib/ace/test_runner/molecules/cli_argument_parser.rb
Overview
Parses CLI arguments to identify package, target, and test files. Handles the complexity of distinguishing between:
-
Direct file paths (./path/file.rb, ../path/file.rb, /abs/path/file.rb)
-
Package-prefixed file paths (ace-bundle/test/file.rb)
-
Package names (ace-bundle)
-
Test targets (atoms, molecules, fast, feat, etc.)
Constant Summary collapse
- KNOWN_TARGETS =
%w[atoms molecules organisms models fast feat all quick].freeze
Instance Attribute Summary collapse
-
#package_dir ⇒ Object
readonly
Returns the value of attribute package_dir.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#test_files ⇒ Object
readonly
Returns the value of attribute test_files.
Instance Method Summary collapse
-
#initialize(argv, package_resolver: nil) ⇒ CliArgumentParser
constructor
A new instance of CliArgumentParser.
-
#known_target?(arg) ⇒ Boolean
Check if an argument is a known test target.
-
#parse ⇒ Hash
Parse arguments and populate package_dir, target, test_files.
Constructor Details
#initialize(argv, package_resolver: nil) ⇒ CliArgumentParser
Returns a new instance of CliArgumentParser.
21 22 23 24 25 26 27 |
# File 'lib/ace/test_runner/molecules/cli_argument_parser.rb', line 21 def initialize(argv, package_resolver: nil) @argv = argv @package_resolver = package_resolver || PackageResolver.new @package_dir = nil @target = nil @test_files = [] end |
Instance Attribute Details
#package_dir ⇒ Object (readonly)
Returns the value of attribute package_dir.
17 18 19 |
# File 'lib/ace/test_runner/molecules/cli_argument_parser.rb', line 17 def package_dir @package_dir end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
17 18 19 |
# File 'lib/ace/test_runner/molecules/cli_argument_parser.rb', line 17 def target @target end |
#test_files ⇒ Object (readonly)
Returns the value of attribute test_files.
17 18 19 |
# File 'lib/ace/test_runner/molecules/cli_argument_parser.rb', line 17 def test_files @test_files end |
Instance Method Details
#known_target?(arg) ⇒ Boolean
Check if an argument is a known test target
54 55 56 |
# File 'lib/ace/test_runner/molecules/cli_argument_parser.rb', line 54 def known_target?(arg) KNOWN_TARGETS.include?(arg) end |
#parse ⇒ Hash
Parse arguments and populate package_dir, target, test_files.
Parsing precedence (order matters for correct classification):
-
Existing files (./path/file.rb, ../path/file.rb) - direct file paths
-
Package-prefixed file paths (ace-bundle/test/file.rb) - sets package + adds file
-
Package names (ace-bundle) - sets package directory
-
Known targets (atoms, molecules, etc.) - sets test target
-
Relative file paths within package (test/file.rb when package is set)
-
Unrecognized args - treated as custom targets for PatternResolver
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ace/test_runner/molecules/cli_argument_parser.rb', line 40 def parse parse_first_argument parse_remaining_arguments result = {} result[:package_dir] = @package_dir if @package_dir result[:target] = @target if @target result[:files] = @test_files unless @test_files.empty? result end |