Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • N nes
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Merge requests 1
    • Merge requests 1
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Jobs
  • Commits
Collapse sidebar
  • Earth SciencesEarth Sciences
  • nes
  • Wiki
  • HowTo_Console_Line_Interface

HowTo_Console_Line_Interface · Changes

Page history
Update HowTo_Console_Line_Interface authored Jul 08, 2025 by Carles Tena's avatar Carles Tena
Hide whitespace changes
Inline Side-by-side
HowTo_Console_Line_Interface.md
View page @ 408f9a84
...@@ -4,11 +4,11 @@ Follow the steps below to add a new command to the NES CLI: ...@@ -4,11 +4,11 @@ Follow the steps below to add a new command to the NES CLI:
### 1. Create a Script for Your Command ### 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. This script should define the function that implements the logic for your command.
```python ```python
# nes/entrypoints/my_function.py # nes/cli/my_function.py
def my_function(args): def my_function(args):
""" """
...@@ -21,10 +21,10 @@ def my_function(args): ...@@ -21,10 +21,10 @@ def my_function(args):
### 2. Expose the Function in `__init__.py` ### 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 ```python
# nes/entrypoints/__init__.py # nes/cli/__init__.py
from .my_function import my_function from .my_function import my_function
...@@ -33,14 +33,14 @@ __all__ = [..., 'my_function'] ...@@ -33,14 +33,14 @@ __all__ = [..., 'my_function']
### 3. Register the Command in `cli.py` ### 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. This function should add the subparser and specify the handler function.
```python ```python
# nes/entrypoints/cli.py # nes/cli/cli.py
def _add_my_function_subparser(subparsers): 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') parser = subparsers.add_parser('my_function', help='Description of the my_function command')
# Add any command-line arguments here # Add any command-line arguments here
...@@ -53,7 +53,7 @@ def _add_my_function_subparser(subparsers): ...@@ -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. Within the `main()` function in `cli.py`, call `_add_my_function_subparser()` to register your command with the CLI.
```python ```python
# nes/entrypoints/cli.py # nes/cli/cli.py
def main(): def main():
... ...
...@@ -85,7 +85,7 @@ nes my_function --option example_value ...@@ -85,7 +85,7 @@ nes my_function --option example_value
or or
```bash ```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. This will execute the `my_function` command with the specified option.
Clone repository
  • Home
  • Tutorials
  • Trainings
  • Development
  • Contribute
  • FAQ