Commander
Client
Client decorator
Registers a class as a client extension point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the client. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
decorator |
The decorator function. |
Command
Command decorator
This decorator is used to register a function as a command. It will automatically generate the command line arguments for the function based on the annotations.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*aliases
|
Optional command aliases. |
()
|
|
model
|
str
|
Optional Pydantic model name for the body parameter. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
decorator |
Callable
|
The decorated function. |
Resource
Resource decorator
Registers a class as a resource and optionally injects scope-specific functionality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource. |
required |
scope
|
str
|
The scope of the resource. Valid values are "portal" or "tenant". Defaults to "portal". |
'portal'
|
client
|
str
|
The client to inject. Defaults to "duplo". |
'duplo'
|
Returns:
| Name | Type | Description |
|---|---|---|
decorator |
The decorator function. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an invalid scope is provided. |
available_clients
Available Clients
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of available client names. |
available_formats
Available Formats
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of available format names. |
available_resources
Available Resources
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of available resources names. |
commands_for
Commands For
Get all command methods decorated with @Command for a given resource.
This function builds a dictionary of all available commands for a resource, including inherited commands from parent classes. Parent class commands are added first to simulate class extension, then the resource's own commands are added, allowing child classes to override parent methods.
The schema is built from the global schema dict which tracks all @Command decorated
methods, and the resources dict which tracks class inheritance relationships.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the resource (e.g., "tenant", "service"). |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dict where keys are method names and values are command metadata dicts containing: - class: The class name where the method is defined - method: The method name - aliases: List of alternative command names |
extract_args
Extract Args
Extract the cli argument annotations from a function. This will only collect the args of type duplocloud.Arg. This list can now be used to generate an argparse.ArgumentParser object.
get_command_schema
Get Command Schema
Given the name of a command (or alias), find the matching schema entry by checking the class and its ancestors via MRO.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
Type
|
The resource class to check. |
required |
command
|
str
|
The command name or alias. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The schema dict with class, method, aliases, model keys. |
Raises:
| Type | Description |
|---|---|
DuploError
|
If the command is not found. |
get_parser
Get Parser
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
List[Arg]
|
A list of Arg objects. |
required |
Returns: An argparse.ArgumentParser object with args from function.
load_client
Load Client
Load a Client class from the entry points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the client. |
required |
Returns: The class of the client.
load_format
Load Format
Load a Formatter function from the entry points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the format. |
'string'
|
Returns: The class of the format.
load_resource
Load Service
Load a Service class from the entry points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the service. |
required |
Returns: The class of the service.