Skip to main content

CLI API

The Cli class is the core component that defines your custom CLI. This page documents the properties and methods of the Cli class.

Cli Class

The Cli class is defined in hexagon/domain/cli.py and uses Pydantic for data validation.

class Cli(BaseModel):
name: str
command: str
entrypoint: EntrypointConfig = EntrypointConfig()
custom_tools_dir: Optional[str] = None
plugins: List[str] = []
options: Optional[dict] = None

Properties

PropertyTypeDescriptionRequired
namestrThe display name of your CLIYes
commandstrThe command used to invoke your CLIYes
entrypointEntrypointConfigConfiguration for the CLI entrypointNo
custom_tools_dirOptional[str]Directory for custom tool implementationsNo
pluginsList[str]List of plugins to useNo
optionsOptional[dict]Additional options for the CLINo

EntrypointConfig Class

The EntrypointConfig class defines how the CLI is executed.

class EntrypointConfig(BaseModel):
shell: Optional[str] = None
pre_command: Optional[str] = None
environ: Dict[str, Any] = {}

Properties

PropertyTypeDescriptionRequired
shellOptional[str]Custom shell to use for commandsNo
pre_commandOptional[str]Command to run before each tool executionNo
environDict[str, Any]Environment variables to setNo

Example

Here's an example of a CLI configuration in YAML:

cli:
name: Team CLI
command: team
custom_tools_dir: ./custom_tools
plugins:
- my_plugin
entrypoint:
shell: /bin/bash
pre_command: source .env
environ:
DEBUG: "true"

And here's how you might create a Cli instance programmatically:

from hexagon.domain.cli import Cli, EntrypointConfig

entrypoint = EntrypointConfig(
shell="/bin/bash",
pre_command="source .env",
environ={"DEBUG": "true"}
)

cli = Cli(
name="Team CLI",
command="team",
entrypoint=entrypoint,
custom_tools_dir="./custom_tools",
plugins=["my_plugin"]
)