Skip to content

improve command flag names and parsing#43

Merged
crhntr merged 9 commits intomainfrom
feat/clarify-flag-usage-by-improving-the-name
Oct 17, 2025
Merged

improve command flag names and parsing#43
crhntr merged 9 commits intomainfrom
feat/clarify-flag-usage-by-improving-the-name

Conversation

@crhntr
Copy link
Copy Markdown
Member

@crhntr crhntr commented Oct 17, 2025

also add verbose mode for muxt version

@crhntr crhntr requested a review from Copilot October 17, 2025 06:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors CLI flag names and parsing, adds a verbose mode to the version command, and updates help/docs and tests to reflect the new conventions.

  • Introduces clear flag categories with new --use-* and --output-* prefixes, and marks older flags as deprecated while keeping them supported.
  • Adds -v/--verbose to the version command and refactors flag parsing into grouped helpers for generate, check, and documentation.
  • Updates help text, docs, and testdata to (mostly) align with the new flags and adds backward-compatibility tests.

Reviewed Changes

Copilot reviewed 72 out of 72 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
internal/cli/help.txt Replaces ad-hoc help with structured usage, commands, and categorized flags; adds verbose flag note.
internal/cli/commands.go Adds grouped flag sets, new/deprecated flag names, new check/documentation configs, and verbose-enabled version command.
internal/cli/commands_test.go Updates tests to new flag names and adds backward-compatibility tests for deprecated flags.
docs/* Broad doc updates for flag naming; some instances now use deprecated names that should be updated.
cmd/muxt/testdata/* Updates end-to-end test scripts to new flags; adds comprehensive and deprecated-flag coverage.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread internal/cli/commands.go Outdated
Comment thread docs/reference/cli.md Outdated
Comment thread docs/reference/cli.md Outdated
Comment thread docs/tutorials/getting-started.md Outdated
Comment thread docs/reference/templates-variable.md Outdated
Comment thread docs/reference/call-parameters.md Outdated
Comment thread docs/prompts/muxt-quick.md
Comment thread docs/how-to/add-logging.md Outdated
@crhntr crhntr force-pushed the feat/clarify-flag-usage-by-improving-the-name branch from beb05f3 to 48a1338 Compare October 17, 2025 06:40
crhntr and others added 8 commits October 16, 2025 23:51
- Update versionCommand signature to accept stderr parameter
- Set flag parsing output to stderr instead of stdout
- Follows CLI best practice: errors to stderr, output to stdout

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace all --find-* flags with --use-* throughout documentation
- Replace --logger with --output-routes-func-with-logger-param as primary flag
- Replace --path-prefix with --output-routes-func-with-path-prefix-param
- Mark old --logger and --path-prefix as deprecated in feature flags table
- Document version command's new -v, --verbose flag for showing Go version
- Update all code examples to use current flag names
- Update quick reference table to reflect current common flags

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- getting-started.md: Update to use --use-receiver-type
- templates-variable.md: Replace --find-templates-variable with --use-templates-variable
- call-parameters.md: Replace --find-receiver-type with --use-receiver-type
- add-logging.md: Update to use --use-receiver-type and --output-routes-func-with-logger-param
  - Add note that --logger is deprecated
  - Update all command examples

All documentation now uses current, non-deprecated flag names.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Refactor flag registration to reduce duplication
  - Extract flag groups into helper functions (addUseFlagsToFlagSet, addOutputFlagsToFlagSet, etc.)
  - Each helper registers flags and handles deprecation marking in one place
  - Reduces ~120 lines of duplicated code across command-specific flag sets

- Split flags by command for better organization
  - All commands support -v/--verbose flag
  - generate: --use-* and --output-* flags
  - check and documentation: --use-* flags only

- Add Go version output to version command
  - Running `muxt version -v` now displays the Go version used to compile muxt
  - Maintains backward compatibility: `muxt version` shows only muxt version

- Update help text to clearly document which flags work with which commands

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add explicit flag tables for check and documentation commands
  - Previously said 'same as generate' which was misleading
  - These commands only support --use-* flags, not --output-* flags
- Add comprehensive deprecated flags reference table
  - Shows all old flag names and their new equivalents
  - Helps users migrate from deprecated flags
- Clarify that check and docs commands support --use-* flags only

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@crhntr crhntr force-pushed the feat/clarify-flag-usage-by-improving-the-name branch from a4adb62 to b5b8d5a Compare October 17, 2025 06:51
@claude
Copy link
Copy Markdown

claude Bot commented Oct 17, 2025

Code Review: PR #43 - Improve command flag names and parsing

Summary

This PR represents a significant improvement to the CLI interface with a thoughtful flag reorganization that enhances usability and maintainability. The changes are well-executed with strong backward compatibility and comprehensive test coverage.

✅ Strengths

1. Excellent Flag Organization

The new --use-* and --output-* prefix convention is a major UX improvement:

  • --use-* flags clearly indicate "what to find in existing code"
  • --output-* flags clearly indicate "what to generate"
  • This semantic grouping makes the CLI self-documenting and intuitive

Example transformation:

# Before (unclear)
--receiver-type=Server --logger --path-prefix

# After (clear intent)
--use-receiver-type=Server --output-routes-func-with-logger-param --output-routes-func-with-path-prefix-param

2. Strong Backward Compatibility

  • All deprecated flags continue to work via pflag.MarkDeprecated()
  • Proper deprecation warnings guide users to new flags
  • Two comprehensive test files ensure both old and new flags work
  • This is a textbook example of managing breaking changes

3. Code Quality & Refactoring

The refactoring in internal/cli/commands.go is excellent:

  • Helper functions (addUseFlagsToFlagSet, addOutputFlagsToFlagSet, etc.) eliminate ~120 lines of duplication
  • Command-specific flag sets (routesFileConfigurationFlagSet, checkFlagSet, documentationFlagSet) provide clear boundaries
  • Single Responsibility Principle: each helper has one clear purpose

4. Test Coverage

Outstanding test additions:

  • deprecated_flags_still_work.txt: Validates backward compatibility
  • new_flag_names_comprehensive.txt: Validates new flag behavior
  • Updated all 50+ existing test files to use new flags
  • Unit tests in commands_test.go cover edge cases

5. Documentation Quality

  • Updated CLI reference with clear flag categorization
  • Added helpful deprecated flags table for migration
  • Updated all how-to guides and tutorials
  • Consistent voice and examples

6. Version Command Enhancement

Adding --verbose flag to show Go version is a nice touch for debugging:

$ muxt version -v
v0.1.0
go version: go1.24

🔍 Code Analysis

Architecture

  • Clean separation between flag definition and validation
  • Command-specific flag sets prevent flag pollution
  • stderr routing for flag parsing errors follows CLI best practices (commands.go:118)

Error Handling

  • Proper identifier validation using token.IsIdentifier()
  • Clear error messages with suffix constants
  • File extension validation for output files

💡 Minor Suggestions

1. Consider Constants for Long Flag Names

The long flag names like outputRoutesFuncWithLoggerParam are verbose but clear. Consider if some could be shortened slightly without losing clarity:

// Current (very explicit)
--output-routes-func-with-logger-param

// Alternative (still clear, slightly shorter)
--output-routes-with-logger

This is purely a suggestion - the current names are defensible for their explicitness.

2. Help Text Consistency

In help.txt line 28-29, consider aligning the descriptions:

--output-routes-func-with-logger-param      Add *slog.Logger parameter
--output-routes-func-with-path-prefix-param Add pathPrefix string parameter

Could be more parallel:

--output-routes-func-with-logger-param      Add *slog.Logger parameter to routes function
--output-routes-func-with-path-prefix-param Add pathPrefix parameter to routes function

3. Test File Naming

The new test files have excellent descriptive names. Consider adding test case numbers or prefixes for easier sorting:

deprecated_flags_still_work.txt
new_flag_names_comprehensive.txt

Could be:

flag_names_01_deprecated_backward_compat.txt
flag_names_02_new_comprehensive.txt

This is optional - current naming is fine.

🔒 Security Review

No security concerns identified

  • No user input is directly executed
  • File path validation prevents directory traversal
  • Flag validation prevents injection of invalid identifiers

⚡ Performance Considerations

No performance impact

  • Flag parsing is O(n) where n is small (number of flags)
  • Deprecated flag handling adds negligible overhead
  • No runtime performance changes to generated code

🐛 Potential Issues

None Found

I did not identify any bugs. The implementation is solid.

📊 Test Coverage Assessment

Excellent coverage:

  • ✅ Backward compatibility thoroughly tested
  • ✅ New flags comprehensively tested
  • ✅ Edge cases covered (invalid identifiers, wrong file extensions)
  • ✅ All existing test data updated consistently
  • ✅ Both unit tests and integration tests present

Breaking Changes

This PR is marked as BREAKING in commits, but the runtime behavior is fully backward compatible due to deprecated flag support. The only "breaking" aspect is:

  • Users will see deprecation warnings when using old flags
  • New flags are the recommended/documented approach

This is the correct approach for evolving a CLI.

Recommendations

  1. Approve and merge - This is high-quality work
  2. Consider adding a migration guide in the release notes
  3. Document the deprecation timeline (when will old flags be removed?)
  4. Consider adding examples in --help output showing the most common use cases

Conclusion

This PR demonstrates excellent software engineering practices:

  • Clear architectural vision (semantic flag prefixes)
  • Strong backward compatibility
  • Comprehensive testing
  • Thorough documentation
  • Clean, maintainable code

The refactoring reduces duplication, improves UX, and maintains stability. Well done! 🎉

Verdict: LGTM

@crhntr crhntr marked this pull request as ready for review October 17, 2025 06:56
@crhntr crhntr merged commit 63c9060 into main Oct 17, 2025
2 checks passed
@crhntr crhntr deleted the feat/clarify-flag-usage-by-improving-the-name branch October 17, 2025 06:57
@claude
Copy link
Copy Markdown

claude Bot commented Oct 17, 2025

Pull Request Review: Improve Command Flag Names and Parsing

Overview

This PR introduces a comprehensive refactoring of the CLI flag naming scheme, transitioning from --find-* and short flags to more descriptive --use-* and --output-* prefixes. The changes improve clarity while maintaining backward compatibility through deprecated flags.

✅ Code Quality & Best Practices

Strengths:

  1. Excellent refactoring structure - The extraction of flag registration into helper functions (addUseFlagsToFlagSet, addOutputFlagsToFlagSet, etc.) significantly reduces duplication and improves maintainability
  2. Clear naming convention - The new --use-* prefix for input flags and --output-* prefix for output flags creates a semantic distinction that makes the CLI more intuitive
  3. Command-specific flag sets - Different commands now correctly expose only relevant flags (e.g., check/docs only get --use-* flags, not --output-* flags)
  4. Proper deprecation handling - Old flags are marked deprecated with helpful messages pointing to replacements using markDeprecated()
  5. Consistent error handling - Flag parsing errors properly use stderr, maintaining Unix conventions (internal/cli/commands.go:118)

Suggestions:

  1. Flag validation consolidation - The identifier validation logic is duplicated across newRoutesFileConfiguration, newCheckConfiguration, and newDocumentationConfiguration. Consider extracting to a shared validation function:
    func validateIdentifier(name, value string) error {
        if value != "" && !token.IsIdentifier(value) {
            return fmt.Errorf(name + errIdentSuffix)
        }
        return nil
    }

🐛 Potential Bugs & Issues

Minor Issues:

  1. Duplicate flag bindings (internal/cli/commands.go:303-308) - Multiple deprecated flags bind to the same config field:

    • deprecatedTemplatesVariable and deprecatedFindTemplatesVariable both bind to g.TemplatesVariable
    • deprecatedReceiverType and deprecatedFindReceiverType both bind to g.ReceiverType
    • deprecatedReceiverTypePackage and deprecatedFindReceiverTypePackage both bind to g.ReceiverPackage

    While this works, it could cause confusion if users mix deprecated flags. The last flag parsed wins, which may be unexpected. Consider documenting this behavior or detecting conflicting flag usage.

  2. Missing validation - useReceiverTypePackage doesn't validate that the value is a valid package path format, unlike other flags that validate identifiers

⚡ Performance Considerations

Assessment: No performance concerns identified.

  • Flag parsing is O(n) where n is number of args - negligible impact
  • Helper function extraction doesn't add overhead as flagSet operations are already function calls
  • No new allocations or unnecessary processing introduced

🔒 Security Concerns

Assessment: No security issues identified.

  • Input validation properly checks identifiers using token.IsIdentifier()
  • File extension validation prevents writing to non-.go files (internal/cli/commands.go:243-245)
  • No injection risks as flags are parsed by pflag library before validation
  • Stderr/stdout separation follows security best practices for preventing information leakage

🧪 Test Coverage

Strengths:

  1. Comprehensive integration tests - Two new testdata files provide excellent coverage:
    • deprecated_flags_still_work.txt - Validates backward compatibility
    • new_flag_names_comprehensive.txt - Tests new flag combinations
  2. Unit test updates - commands_test.go updated to test both new and deprecated flags (lines 19-62)
  3. Real-world scenarios - Test files include full go modules with template rendering and HTTP testing
  4. Documentation sync - All 72 files updated to use new flag names, ensuring docs match implementation

Gaps:

  1. Missing test for flag conflicts - No test validates behavior when mixing deprecated and new flags (e.g., --receiver-type=A --use-receiver-type=B)
  2. Missing negative test for package validation - No test for invalid --use-receiver-type-package values
  3. Version verbose flag testing - While implemented (internal/cli/commands.go:115-142), no dedicated test in commands_test.go validates the -v/--verbose flag behavior for version command

📋 Additional Observations

Documentation Updates:

  • ✅ Excellent: CLI reference docs updated with new flag tables
  • ✅ Excellent: Deprecated flags table added for migration guidance
  • ✅ Excellent: All tutorials and how-to guides updated consistently
  • ⚠️ Minor: The help text could benefit from examples showing both --use-* and --output-* flags together

Breaking Change Communication:

  • The commits use conventional commit format with ! to signal breaking changes: feat(cli)!: rename flags
  • However, this is actually NOT a breaking change due to backward compatibility
  • Consider using feat(cli): without ! since deprecated flags ensure no breaking changes

🎯 Recommendations

High Priority:

  1. Add test coverage for mixed deprecated/new flag usage
  2. Document the "last flag wins" behavior for deprecated aliases

Medium Priority:
3. Extract identifier validation logic to reduce duplication
4. Add package path validation for --use-receiver-type-package
5. Add unit test for version -v/--verbose flag

Low Priority:
6. Remove ! from conventional commit messages or add a note that backward compatibility is maintained
7. Consider adding usage examples to help text showing common flag combinations

✨ Summary

This is a high-quality refactoring that significantly improves the CLI's usability and maintainability. The code follows Go best practices, maintains excellent backward compatibility, and includes comprehensive test coverage. The semantic distinction between --use-* (input) and --output-* (generated names) flags is a substantial UX improvement.

The minor issues identified are primarily about test coverage completeness and minor validation gaps - the core implementation is solid and production-ready.

Recommendation:Approve with minor suggestions

Great work on maintaining backward compatibility while improving the interface! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants