feat(cmd): parse matrix flags#111
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #111 +/- ##
==========================================
- Coverage 80.48% 80.47% -0.01%
==========================================
Files 36 37 +1
Lines 2034 2095 +61
==========================================
+ Hits 1637 1686 +49
- Misses 290 297 +7
- Partials 107 112 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c74f1fe to
b28e3a2
Compare
There was a problem hiding this comment.
Code Review
This pull request implements CLI matrix flag support for the llar make and llar test commands, allowing users to define build dimensions such as architecture and OS directly through command-line arguments. This is supported by a new internal parser and updated command logic, along with design documentation and tests. The review feedback identifies a logic inconsistency in the parser that prevents values starting with hyphens from being accepted for certain matrix flags. Furthermore, the MatrixStr field added to modules.Options appears to be unused in the current implementation, suggesting it may be dead code.
72259dd to
6fc1bd9
Compare
|
/review |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces dynamic matrix flag resolution for the make and test commands in llar. It extracts unknown long flags from the command-line arguments to build a custom build matrix, falling back to the host matrix combination when none are provided. The review feedback highlights two key areas for improvement in the argument parsing logic: first, using cmd.CalledAs() instead of cmd.Name() to ensure the command is correctly located in os.Args even when invoked via an alias; second, enhancing the short flag parser to iterate through all characters of a grouped short flag to prevent unknown flags from being silently ignored.
Allow passing target matrix dimensions via unknown long flags (e.g. --os linux --arch amd64) and --matrix-<key> prefix for conflicts with known flags. Uses Cobra's FParseErrWhitelist to silently consume unknown flags, then extracts them from os.Args via cmd.Flags().Lookup(). Closes xgo-dev#113
Replace hand-written arg scanner with go-flags library to handle edge cases (negative values, --, = forms) correctly via UnknownOptionHandler. Closes xgo-dev#113
1e02822 to
55a2f28
Compare
|
/review |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces dynamic matrix flag parsing for the make and test commands using the github.com/jessevdk/go-flags library. It extracts unknown long flags as matrix dimensions while ignoring known Cobra flags. The review feedback highlights several critical and medium-severity issues: modifying the global os.Args in tests without restoring it can cause side effects, cmd.CalledAs() should fall back to cmd.Name() if empty to prevent incorrect index resolution, and redundant shorthand lookups can be simplified.
Searching os.Args for cmd.CalledAs() is fragile when the subcommand name appears as a flag value earlier in the args. Use CommandPath() word count to determine the fixed depth and slice os.Args directly. Closes xgo-dev#113
63aa5be to
b40d4d8
Compare
|
/gemini review |
|
/review |
There was a problem hiding this comment.
Code Review
This pull request introduces dynamic matrix flag parsing for the llar CLI tool, allowing unknown long flags to be extracted as matrix dimensions. It adds a new utility matrix_flags.go along with tests, and integrates this logic into the make and test commands. The code reviewer provided several valuable suggestions to improve argument parsing: changing cobra.ExactArgs(1) to cobra.ArbitraryArgs to prevent validation failures when flags take arguments, updating the extraction helpers to return remaining positional arguments cleanly, and adding a safety check to prevent potential panics.
There was a problem hiding this comment.
Review Summary
Good feature addition with solid test coverage. The separation of extractMatrixFlags (testable with explicit args) from resolveMatrixStr is well-designed, error messages are clear, and the FParseErrWhitelist usage is correct.
Key concerns:
- Matrix values lack validation — keys are regex-checked but values flow unsanitized into filesystem paths and separator-delimited combination strings
- Discarded error from
parser.ParseArgs - Silent matrix dimension capture — any typo of a known flag (e.g.
--vebose) silently becomes a matrix dimension with no warning
| val = args[0] | ||
| args = args[1:] | ||
| } | ||
| if val == "" { | ||
| matrixErr = fmt.Errorf("missing value for matrix flag --%s", option) | ||
| return args, nil | ||
| } | ||
| dims[key] = val |
There was a problem hiding this comment.
Value validation missing. Keys are validated with matrixKeyRE, but values are unconstrained beyond the empty-string check. Since matrixStr flows into filesystem paths (cache dirs, install paths) and into -/|-delimited combination strings:
- A value like
../../etccould cause path traversal in cache lookups - A value containing
-(the Combinations separator) could collide with legitimate multi-dim combinations
Consider adding a value regex similar to keys, or at minimum rejecting values containing /, \\, .., and |.
| return args, nil | ||
| } | ||
|
|
||
| parser.ParseArgs(subArgs) |
There was a problem hiding this comment.
The error returned by parser.ParseArgs() is discarded. While UnknownOptionHandler handles most cases via the matrixErr closure, the parser itself could return errors for other reasons (e.g., internal parse failures). Consider checking the error or adding a comment explaining why it's intentionally ignored.
| parser.ParseArgs(subArgs) | |
| if _, parseErr := parser.ParseArgs(subArgs); parseErr != nil && matrixErr == nil { | |
| // go-flags may return parse errors not captured by UnknownOptionHandler | |
| matrixErr = parseErr | |
| } |
Closes #113