Skip to content

Instantly share code, notes, and snippets.

@ryan-williams
Last active November 9, 2025 01:12
Show Gist options
  • Select an option

  • Save ryan-williams/8e1ec5a8de9e5789a5a749a72936c3ed to your computer and use it in GitHub Desktop.

Select an option

Save ryan-williams/8e1ec5a8de9e5789a5a749a72936c3ed to your computer and use it in GitHub Desktop.

runsascoded/ghpr#6 Improve help text, refactor command registration, and fix test assertions

This PR includes three improvements to the ghpr codebase:

1. Better Help Text and Validation

  • Draft flag validation - Added error when using -d without -y, since draft mode is incompatible with web editor
  • Clearer help text - Updated create command and flag descriptions to clearly explain the three modes:
    • Default (no -y): Interactive web editor (waits for user)
    • -y once: Create via API then view result
    • -yy twice: Create silently
  • Auto gist push - create now automatically pushes to gist remote after finalizing PR/Issue

2. Decorator Syntax Refactoring

Converted all 10 command register() functions from deeply nested function calls to clean vertical decorator stacks:

# Before
cli.command()(
    flag('-g', '--gist')(
        flag('-n', '--dry-run')(
            command
        )
    )
)

# After
@cli.command()
@flag('-n', '--dry-run')
@flag('-g', '--gist')
def command_cmd(dry_run, gist):
    command(gist, dry_run)

This makes the code much more readable and maintainable. Net result: -32 lines of code!

3. Comprehensive Test Assertion Improvements

Fixed all test assertions across the test suite to use precise equality checks instead of fragile substring matching:

  • test_import.py - Used regex to extract exact command names from CLI help, fixed shell integration checks
  • test_create.py - Changed to exact tuple comparisons for gh command arguments, added missing mocks for push() call
  • test_files.py - Replaced all substring checks with full content equality, fixed newline handling
  • test_gist.py - Replaced substring checks with exact equality, fixed gist footer formatting expectations

Impact: Fixed 51+ problematic assertions that used assert x in y patterns. All 92 tests now pass with precise, maintainable assertions that clearly document expected values

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