... | ... | @@ -4,11 +4,11 @@ Follow the steps below to add a new command to the NES CLI: |
|
|
|
|
|
### 1. Create a Script for Your Command
|
|
|
|
|
|
Create a new Python script in the `nes/entrypoints/` directory, such as `my_function.py`.
|
|
|
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.
|
|
|
|
|
|
```python
|
|
|
# nes/entrypoints/my_function.py
|
|
|
# nes/cli/my_function.py
|
|
|
|
|
|
def my_function(args):
|
|
|
"""
|
... | ... | @@ -21,10 +21,10 @@ def my_function(args): |
|
|
|
|
|
### 2. Expose the Function in `__init__.py`
|
|
|
|
|
|
To make your function available for CLI registration, import and expose it in `nes/entrypoints/__init__.py`.
|
|
|
To make your function available for CLI registration, import and expose it in `nes/cli/__init__.py`.
|
|
|
|
|
|
```python
|
|
|
# nes/entrypoints/__init__.py
|
|
|
# nes/cli/__init__.py
|
|
|
|
|
|
from .my_function import my_function
|
|
|
|
... | ... | @@ -33,14 +33,14 @@ __all__ = [..., 'my_function'] |
|
|
|
|
|
### 3. Register the Command in `cli.py`
|
|
|
|
|
|
Add a helper function in `nes/entrypoints/cli.py` to register your command's subparser.
|
|
|
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.
|
|
|
|
|
|
```python
|
|
|
# nes/entrypoints/cli.py
|
|
|
# nes/cli/cli.py
|
|
|
|
|
|
def _add_my_function_subparser(subparsers):
|
|
|
from nes.entrypoints import my_function
|
|
|
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
|
... | ... | @@ -53,7 +53,7 @@ def _add_my_function_subparser(subparsers): |
|
|
Within the `main()` function in `cli.py`, call `_add_my_function_subparser()` to register your command with the CLI.
|
|
|
|
|
|
```python
|
|
|
# nes/entrypoints/cli.py
|
|
|
# nes/cli/cli.py
|
|
|
|
|
|
def main():
|
|
|
...
|
... | ... | @@ -85,7 +85,7 @@ nes my_function --option example_value |
|
|
or
|
|
|
|
|
|
```bash
|
|
|
python -m nes.entrypoints.cli my_function --option example_value
|
|
|
python -m nes.cli.cli my_function --option example_value
|
|
|
```
|
|
|
|
|
|
This will execute the `my_function` command with the specified option. |