-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add command and option sections (#136)
- Loading branch information
Showing
15 changed files
with
614 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Grouping command options | ||
======================== | ||
|
||
.. contents:: Table of Contents | ||
:class: this-will-duplicate-information-and-it-is-still-useful-here | ||
:local: | ||
:backlinks: none | ||
:depth: 3 | ||
|
||
In cases when a command has many options, it can be useful to divide these | ||
options into different sections which are displayed on the command help page. | ||
For instance, basic and advanced options. | ||
|
||
The :py:func:`.section` decorator can be used to define these sections for a command. | ||
|
||
.. seealso:: | ||
|
||
:py:obj:`.Group.__sections__()` can be used to similarly partition commands | ||
and subgroups displayed on a :py:class:`.Group` help page. | ||
|
||
---- | ||
|
||
API reference | ||
------------- | ||
|
||
.. autofunction:: feud.decorators.section |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (c) 2023-2025 Feud Developers. | ||
# Distributed under the terms of the MIT License (see the LICENSE file). | ||
# SPDX-License-Identifier: MIT | ||
# This source code is part of the Feud project (https://feud.wiki). | ||
|
||
from feud import click | ||
from feud._internal import _command | ||
|
||
|
||
def get_group(__cls: type, /) -> click.Group: # type[Group] | ||
func: callable = __cls.__main__ | ||
if isinstance(func, staticmethod): | ||
func = func.__func__ | ||
|
||
state = _command.CommandState( | ||
config=__cls.__feud_config__, | ||
click_kwargs=__cls.__feud_click_kwargs__, | ||
is_group=True, | ||
aliases=getattr(func, "__feud_aliases__", {}), | ||
envs=getattr(func, "__feud_envs__", {}), | ||
names=getattr( | ||
func, | ||
"__feud_names__", | ||
_command.NameDict(command=None, params={}), | ||
), | ||
overrides={ | ||
override.name: override | ||
for override in getattr(func, "__click_params__", []) | ||
}, | ||
) | ||
|
||
# construct command state from signature | ||
_command.build_command_state( | ||
state, func=func, config=__cls.__feud_config__ | ||
) | ||
|
||
# generate click.Group and attach original function reference | ||
command = state.decorate(func) | ||
command.__func__ = func | ||
command.__group__ = __cls | ||
return command |
Oops, something went wrong.