CLI
diracx-cli
The diracx-cli
is a command-line interface built on diracx-client
and diracx-api
for direct interaction with services. It uses Typer for creating CLI commands and Rich for enhanced content display.
CLI Commands
CLI commands are located in diracx-cli/src/diracx/cli/
. To create a CLI command:
- Import
AsyncDiracClient
and/ordiracx-api
. - Import
utils.AsyncTyper
. - Use the
@app.async_command
decorator to define commands.
For adding a new command, it needs to be added to one of the following entrypoint:
[project.entry-points."diracx.cli"]
jobs = "diracx.cli.jobs:app"
config = "diracx.cli.config:app"
[project.entry-points."diracx.cli.hidden"]
internal = "diracx.cli.internal:app"
Example
from .utils import AsyncTyper
from diracx.client.aio import AsyncDiracClient
app = AsyncTyper()
@app.async_command()
async def submit(jdl: list[FileText]):
async with AsyncDiracClient() as client:
...
For more details on Typer and Rich options, refer to their Typer documentation and Rich documentation.
Associating Commands and Subcommands
TODO: WRONG
-
Commands without subcommands (e.g.,
dirac login
) should be implemented directly insrc/diracx/__init__.py
and decorated withapp.async_command()
. -
Commands with subcommands (e.g.,
dirac jobs submit
) should have their own modules insrc/diracx/<command>
and useAsyncTyper
. -
To associate the command with
dirac
, import the module insrc/diracx/__init__.py
:
Users can then call the CLI: