CLI Overview
The pydoover CLI provides a command-line interface for interacting with running gRPC servers on Doover devices. It allows you to test communications, read and write I/O, and interact with device agent channels directly from the terminal.
Installation
The CLI is included with the pydoover package. After installing pydoover, the pydoover command becomes available:
pip install pydoover
Basic Usage
The CLI uses a subcommand structure where you first specify the interface (platform, device_agent, or modbus) and then the specific command:
pydoover <interface> <command> [options]
Getting Help
View available interfaces and options:
pydoover --help
View commands for a specific interface:
pydoover platform --help pydoover device_agent --help pydoover modbus --help
Available Interfaces
The CLI provides access to three main gRPC interfaces:
Platform Interface
Interact with the Platform Interface container for device I/O operations:
pydoover platform <command> [options]
The platform interface provides access to:
- Digital inputs and outputs
- Analog inputs and outputs
- System information (voltage, power, temperature)
- Device location
- Shutdown and reboot controls
Device Agent Interface
Interact with the Device Agent container for cloud connectivity and channel operations:
pydoover device_agent <command> [options]
The device agent interface provides access to:
- Channel aggregates and subscriptions
- Message publishing
- Connection status
- Temporary API tokens
Modbus Interface
Interact with the Modbus Interface container for modbus device communication:
pydoover modbus <command> [options]
The modbus interface provides access to:
- Bus management (open/close)
- Register reading and writing
- Bus status monitoring
Connection Options
Each interface accepts a URI option to specify the gRPC server address:
# Platform interface (default: localhost:50053) pydoover platform --uri localhost:50053 test_comms # Device agent interface (default: 127.0.0.1:50051) pydoover device_agent --uri 127.0.0.1:50051 test_comms # Modbus interface (default: 127.0.0.1:50054) pydoover modbus --uri 127.0.0.1:50054 test_comms
Architecture
The CLI is built on Python's argparse library and uses a SubSection class to organize gRPC interface methods as CLI subcommands. Methods decorated with @command() in the interface classes are automatically registered as CLI commands.
Entry Point
The CLI entry point is defined in the pydoover package:
from pydoover.cli import CLI
def entrypoint():
CLI().main()
This is registered as the pydoover console script during package installation.
Command Registration
Commands are registered using the @command() decorator from pydoover.cli.decorators:
from pydoover.cli.decorators import command as cli_command
class MyInterface:
@cli_command()
def my_command(self, arg1: str, arg2: int = 10):
"""Command description.
Parameters
----------
arg1 : str
Description of arg1
arg2 : int
Description of arg2 (default: 10)
"""
# Implementation
The decorator:
- Marks the method as a CLI command
- Extracts the command name from the method name (or custom name)
- Parses docstrings for parameter descriptions
- Handles argument type conversion
SubSection Class
The SubSection class organizes interface methods into CLI subcommands:
from pydoover.cli.sub_section import SubSection
from pydoover.docker.platform import PlatformInterface
subsection = SubSection(
PlatformInterface,
name="platform",
description="Interact with a running Platform Interface container"
)
The SubSection class:
- Introspects the interface class for decorated commands
- Creates argparse subparsers for each command
- Handles parameter type conversion
- Manages gRPC connection setup
Error Handling
By default, the CLI displays simplified error messages. For debugging, use the --enable-traceback flag on any command to see the full stack trace:
pydoover platform get_di 0 --enable-traceback
Requirements
The CLI requires the Docker interfaces to be available. If the gRPC dependencies are not installed, you will see:
Docker interfaces not found. GRPC CLI support will not be available.
Ensure you have installed pydoover with the necessary dependencies for gRPC support.