Skip to content

Make a command's help category public as Cmd.get_command_category() - #1856

Merged
tleonhardt merged 3 commits into
mainfrom
public-command-category
Dec 2, 2026
Merged

tleonhardt merged 3 commits into
mainfrom
public-command-category

Conversation

@tleonhardt

Copy link
Copy Markdown
Member

Makes Cmd._get_command_category() public as Cmd.get_command_category(). It returns the help
category which help lists a command under.

An application which describes its own commands needs a command's category, and until now the only
way to get it was the private method. #1852 is the first such case.

What changes

  • Cmd.get_command_category(func) is the old _get_command_category() under a public name,
    with the same behavior. Its docstring now gives the order in which the category is found:
    1. a category given with @with_category or categorize()
    2. the DEFAULT_CATEGORY of the class which defines the command, which may be a CommandSet or a
      base class
    3. the application's own DEFAULT_CATEGORY, when the defining class has none, as with a plain
      mixin
  • The callers in cmd2.py use the new name. The private name is removed, not kept as an alias,
    since it was never public API. No caller of it remains in cmd2, docs or examples:
    git grep -n _get_command_category -- cmd2 docs examples prints nothing.
  • Docs: docs/features/help.md says how to find a command's category.
  • Tests: tests/test_categories.py covers each of the three sources of the category, and that
    the private name is gone.
  • CHANGELOG: an entry under a new 4.5.0 (TBD) heading.

Merging

This goes in 4.5.0, so it should be merged only after 4.4.5 is released. Until then it is a draft.

#1855 is built on this branch.

Design documents

In the python-cmd2/design repository, this is Stage 1 of:

Part of #1852.

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.76%. Comparing base (c0d8e91) to head (5f056e3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1856   +/-   ##
=======================================
  Coverage   99.76%   99.76%           
=======================================
  Files          23       23           
  Lines        6773     6773           
=======================================
  Hits         6757     6757           
  Misses         16       16           
Flag Coverage Δ
unittests 99.76% <100.00%> (ø)

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

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

@tleonhardt
tleonhardt marked this pull request as ready for review December 2, 2026 19:52
@tleonhardt
tleonhardt merged commit 9963c78 into main Dec 2, 2026
28 checks passed
@tleonhardt
tleonhardt deleted the public-command-category branch December 2, 2026 19:53
@tleonhardt
tleonhardt restored the public-command-category branch December 2, 2026 19:53
@tleonhardt
tleonhardt deleted the public-command-category branch December 2, 2026 19:53
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