-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: load available CLI commands dynamically
- Loading branch information
1 parent
b18bb0f
commit 4ed7067
Showing
11 changed files
with
164 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Package of mostly self-contained commands. | ||
The CLI loads the modules in this package dynamically at startup. | ||
Valid command modules in this package should implement an interface like the following: | ||
__doc__ = "Perform magic." | ||
def setup_parser(parser: argparse.ArgumentParser) -> None: | ||
# Optional additions to this command's argparse subparser. | ||
# For example: | ||
parser.add_argument("-x", action="store_true", help="Enable effects") | ||
def run(args: argparse.Namespace) -> None: | ||
# Implementation of this command's functionality. | ||
# For example" | ||
shell_utils.run_command(["echo", "hello"]) | ||
The module's name will be the CLI's positional argument to invoke the command. | ||
The module's __doc__ will be the help text for the CLI's help command. | ||
For example, invoking `quipucordsctl --help` with the example code above in | ||
a module file named `magic.py` may produce output like the following: | ||
$ quipucordsctl --help | ||
usage: quipucordsctl [-h] {install,magic} ... | ||
positional arguments: | ||
{install,magic} | ||
install Install the Quipucords server. | ||
magic Perform magic. | ||
options: | ||
-h, --help show this help message and exit | ||
$ quipucordsctl magic --help | ||
usage: quipucordsctl magic [-h] [-x] | ||
options: | ||
-h, --help show this help message and exit | ||
-x Enable effects | ||
If the module has attribute `NOT_A_COMMAND=True` set, it will not be included | ||
by argparse as a valid positional argument. | ||
""" |
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 |
---|---|---|
@@ -1 +1,17 @@ | ||
"""Logic for the "uninstall" command.""" | ||
"""Uninstall the server.""" | ||
|
||
import argparse | ||
import logging | ||
|
||
from .. import settings | ||
|
||
__doc__ = f"Uninstall the {settings.SERVER_SOFTWARE_NAME} server." | ||
|
||
logger = logging.getLogger(__name__) | ||
NOT_A_COMMAND = True # Until we complete the implementation. | ||
|
||
|
||
def run(args: argparse.Namespace) -> None: | ||
"""Uninstall the server.""" | ||
logger.warning("%s is not yet implemented.", __name__) | ||
# TODO Implement this. |
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
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