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

fix: Centralize command setup code. #33

Merged
merged 2 commits into from
Oct 22, 2023
Merged

Conversation

DanCardin
Copy link
Owner

Adds a (currently undocumented and not explicitly exported collect function in cappa.base.

Upon seeing #30, it occurred to me that at the very least there's a decent chunk of code being duplicated between argparse and the native backend.

  • It makes the code simpler, reusing more between the parsers
  • because it moves logic upstream of argeparse that was previously built into the native parger, it enables using the "native" rich help text generation when using the argparse backend
  • incidentally it also helps simplify the situation in question: Forcing colors? #30 which required a decent chunk of code to output help text without also performing parsing.

Base automatically changed from dc/helptext-cleanup to main October 22, 2023 12:12
@DanCardin DanCardin force-pushed the dc/central-command-collection branch from 17c2a34 to ff137f4 Compare October 22, 2023 12:12
@coveralls
Copy link

coveralls commented Oct 22, 2023

Pull Request Test Coverage Report for Build 6603742067

  • 38 of 38 (100.0%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 6603736997: 0.0%
Covered Lines: 1558
Relevant Lines: 1558

💛 - Coveralls

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Oct 22, 2023

Great! IIUC, we can now do this?

from cappa.base import collect
from cappa.help import format_help
from cappa.output import Output

from pkg.cli import CommandMain

Output.from_theme().output(format_help(collect(CommandMain)))

The individual subcommand help is shown in help text, which makes the
subcommand-object level help superfluous.
@DanCardin DanCardin force-pushed the dc/central-command-collection branch from ff137f4 to 4e9c05f Compare October 22, 2023 12:20
@DanCardin
Copy link
Owner Author

Yup! Probably once i've decided its "done", collect will be exposed at the root of the package. I'm not thrilled necessarily at how it currently composes with parse and such, but tl;dr yes :P

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Oct 22, 2023

OK, great! I've opened #35 as a follow up 🙂

@DanCardin DanCardin merged commit df0467d into main Oct 22, 2023
6 checks passed
@DanCardin DanCardin deleted the dc/central-command-collection branch October 22, 2023 13:45
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.

None yet

3 participants