Skip to content

Use Typer for argument parsing#138

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-137
Draft

Use Typer for argument parsing#138
Copilot wants to merge 4 commits intomainfrom
copilot/fix-137

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jul 7, 2025

Migrates the CLI from argparse to Typer to simplify argument handling while preserving all existing functionality and maintaining backward compatibility.

Key Features Delivered

Each arg is declared once - Using Annotated types and reusable option definitions
Subcommands are supported - Multi-level subcommands working (aci get ids)
Inline args or environment variables - --my-arg or MY_ARG="" both supported
Interactive prompting - Missing required args prompt user automatically
Help at all levels - --help works at main, subcommand, and sub-subcommand levels

Before (argparse)

$ c-aci-testing target create --help
usage: Utilities for testing workflows involving Confidential ACI. target [-h]

options:
  -h, --help  show this help message and exit

After (Typer)

$ c-aci-testing target create --help
Usage: c-aci-testing target create [OPTIONS] [TARGET_PATH]

 Create a new target.

╭─ Arguments ──────────────────────────────────────────────────────────────╮
│   target_path      [TARGET_PATH]  The relative path to the c-aci-testing │
│                                   target directory [default: /current]   │
╰──────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────╮
│ --name  -n      TEXT  The name of the new target [default: example]      │
│ --help                Show this message and exit.                        │
╰──────────────────────────────────────────────────────────────────────────╯

Implementation Highlights

  • Environment Variable Integration: Clear UI feedback showing [env var: REGISTRY] in help
  • Interactive Prompting: Uses typer.prompt() for missing required arguments
  • Rich Help Formatting: Proper command grouping with description boxes
  • Key=Value Parameters: Custom parsing for --parameters key1=value1 key2=value2
  • Backward Compatibility: Existing tests continue to work with old parameter functions
  • Minimal Changes: Preserved all command names, argument structure, and behavior

Technical Details

  • Added typer~=0.12.0 dependency
  • Created new typer_parser.py with complete CLI implementation
  • Updated main.py to use Typer instead of argparse
  • Implemented custom key=value parsing equivalent to ExtendDictAction
  • Preserved all existing parameter functions for test compatibility

All existing functionality works identically, but with improved user experience through better help formatting, environment variable visibility, and interactive prompting.

Fixes #137.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits July 7, 2025 13:18
Co-authored-by: DomAyre <8723193+DomAyre@users.noreply.github.com>
Co-authored-by: DomAyre <8723193+DomAyre@users.noreply.github.com>
…tion

Co-authored-by: DomAyre <8723193+DomAyre@users.noreply.github.com>
Copilot AI changed the title [WIP] Use Typer for argument parsing Use Typer for argument parsing Jul 7, 2025
Copilot AI requested a review from DomAyre July 7, 2025 13:27
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.

Use Typer for argument parsing

2 participants