Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(experimental) Propagate helptext into subcommands #227

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

brentyi
Copy link
Owner

@brentyi brentyi commented Jan 8, 2025

discussed in #221

from dataclasses import dataclass
import tyro

@dataclass(frozen=True)
class AdamConfig:
    adam_foo: float = 1.0

@dataclass(frozen=True)
class SGDConfig:
    sgd_foo: float = 1.0

@dataclass(frozen=True)
class Config:
    optimizer: AdamConfig | SGDConfig = AdamConfig()
    """Optimizer configuration."""

tyro.cli(Config)

root helptext (unchanged):

usage: ex.py [-h] [{optimizer:adam-config,optimizer:sgd-config}]

╭─ options ─────────────────────────────────────────────────╮
│ -h, --help        show this help message and exit         │
╰───────────────────────────────────────────────────────────╯
╭─ optional subcommands ────────────────────────────────────╮
│ Optimizer configuration. (default: optimizer:adam-config) │
│ ───────────────────────────────────────────────────────── │
│ [{optimizer:adam-config,optimizer:sgd-config}]            │
│     optimizer:adam-config                                 │
│     optimizer:sgd-config                                  │
╰───────────────────────────────────────────────────────────╯

subcommand helptext ("Optimizer configuration" is new):

usage: ex.py optimizer:adam-config [-h] [--optimizer.adam-foo FLOAT]

╭─ options ─────────────────────────────────────────╮
│ -h, --help        show this help message and exit │
╰───────────────────────────────────────────────────╯
╭─ optimizer options ───────────────────────────────╮
│ Optimizer configuration.                          │
│ ────────────────────────────────                  │
│ --optimizer.adam-foo FLOAT                        │
│                   (default: 1.0)                  │
╰───────────────────────────────────────────────────╯

Copy link

codecov bot commented Jan 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.82%. Comparing base (0c2cb26) to head (240be27).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #227   +/-   ##
=======================================
  Coverage   99.82%   99.82%           
=======================================
  Files          28       28           
  Lines        2304     2304           
=======================================
  Hits         2300     2300           
  Misses          4        4           
Flag Coverage Δ
unittests 99.82% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

1 participant