Skip to content

Refactor wptgen/main.py by extracting CLI commands and shared options #462

@DanielRyanSmith

Description

@DanielRyanSmith

Background & Motivation

The wptgen/main.py file has grown significantly and currently houses the definitions and logic for all CLI commands (e.g., generate, chromestatus, audit, doctor, config) along with global configurations and helper functions. Furthermore, a substantial amount of code duplication exists because many commands (generate, audit, chromestatus) share identical CLI flag definitions (using Typer's Annotated[..., typer.Option(...)]).

As more features and commands are added, this file will become increasingly difficult to navigate and maintain. Splitting the CLI command definitions into separate, focused modules and extracting shared argument definitions will drastically reduce boilerplate, ensure CLI flag consistency, and improve code organization.

Proposed Changes

  • Create a new directory structure for CLI components (e.g., wptgen/cli/).
  • Deduplicate Typer Options: Create a wptgen/cli/options.py (or arguments.py) module to define shared typer.Option aliases (e.g., ConfigOption, ProviderOption, UseReasoningOption). Update all command signatures to use these shared types.
  • Extract Commands: Move the specific command logic out of wptgen/main.py and into their own module files. For example:
    • wptgen/cli/commands/generate.py (for the generate and generate-single commands)
    • wptgen/cli/commands/chromestatus.py
    • wptgen/cli/commands/audit.py
    • wptgen/cli/commands/config.py (for the config sub-app commands)
    • wptgen/cli/commands/system.py (for doctor, clear-cache, version, init, and list-models)
  • Extract Helpers: Extract shared helper functions (e.g., _check_workflow_flags, _print_workflow_banner, _workflow_error_handler, _execute_workflow) into an internal helper module like wptgen/cli/core.py to ensure clean imports and code reuse.
  • Simplify main.py: Refactor wptgen/main.py so that its primary responsibility is acting as the root CLI entry point, initializing the Typer app, applying logging configuration, and wiring up the subcommands (using app.add_typer() or direct function imports) without changing the existing command-line API structure.

Acceptance Criteria

  • A new directory for CLI modules is created and integrated.
  • Shared Typer options are extracted into a common file and reused across command signatures.
  • All CLI commands currently in main.py are relocated to separate, logically grouped modules.
  • All shared helper methods are extracted to an appropriate common file.
  • The CLI behavior, command structure, and available flags remain completely unchanged for the end user.
  • The make presubmit (or equivalent test/lint/typecheck commands) pass without errors.

This issue description was drafted by Gemini

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions