Repository navigation
HowTo_Console_Line_Interface
Follow the steps below to add a new command to the NES CLI:
Create a new Python script in the nes/cli/ directory, such as my_function.py.
This script should define the function that implements the logic for your command.
# nes/cli/my_function.py
def my_function(args):
"""
Implement the logic for your command here.
Args:
args: Parsed command-line arguments.
"""
print("Executing my_function with arguments:", args)To make your function available for CLI registration, import and expose it in nes/cli/__init__.py.
# nes/cli/__init__.py
from .my_function import my_function
__all__ = [..., 'my_function']Add a helper function in nes/cli/cli.py to register your command's subparser.
This function should add the subparser and specify the handler function.
# nes/cli/cli.py
def _add_my_function_subparser(subparsers):
from nes.cli import my_function
parser = subparsers.add_parser('my_function', help='Description of the my_function command')
# Add any command-line arguments here
parser.add_argument('--option', type=str, help='An example option')
parser.set_defaults(func=my_function)Within the main() function in cli.py, call _add_my_function_subparser() to register your command with the CLI.
# nes/cli/cli.py
def main():
...
# Add subcommands
_add_check_subparser(subparsers)
_add_reorder_subparser(subparsers)
# Register your custom command here
_add_my_function_subparser(subparsers)
...- Update the wiki User Guide with the new command and its link.
- Create a new wiki page for your command, following the format of existing pages.
After testing and documenting your command, submit a merge request to the master branch.
After completing the steps above, you can run your new command from the terminal:
nes my_function --option example_valueor
python -m nes.cli.cli my_function --option example_valueThis will execute the my_function command with the specified option.