Architecture

Toast-cli follows a plugin-based architecture that makes it easy to extend and maintain.

  1. Entry points
    toast or python -m toast
  2. Click command group
    toast/__init__.py discovers plugins; helpers.py supplies help and version output.
  3. BasePlugin
    Registers command arguments and converts expected failures into nonzero CLI exits.
  4. Plugins
    am · cdw · ctx · dot · env · git · prompt · region · ssm
  5. Shared operations
    utils.py: command execution, secret masking, atomic file writes.
    storage.py: parallel S3 + SSM reads for dot and prompt; writes to S3.
  6. External tools
    Git, kubectl, AWS CLI (STS, EC2, EKS, S3, SSM).
Commands flow through a shared plugin boundary. Each plugin calls only the tools it needs.

Package Structure

toast-cli/
  ├── setup.py            # Package setup script
  ├── pyproject.toml      # Build system requirements
  ├── MANIFEST.in         # Additional files to include
  ├── VERSION             # Version information
  ├── README.md           # Project documentation
  ├── ARCHITECTURE.md     # Architecture documentation
  ├── LICENSE             # License information
  ├── docs/               # Documentation website files
  │   ├── CNAME           # Custom domain configuration
  │   ├── favicon.ico     # Website favicon
  │   ├── index.html      # Main documentation page
  │   ├── css/            # Stylesheet files
  │   └── js/             # JavaScript files
  └── toast/              # Main package
      ├── __init__.py     # Package initialization and CLI entry point
      ├── __main__.py     # Entry point for running as a module
      ├── helpers.py      # Helper functions and custom UI elements
      └── plugins/        # Plugin modules
          ├── __init__.py
          ├── base_plugin.py
          ├── am_plugin.py
          ├── cdw_plugin.py
          ├── ctx_plugin.py
          ├── dot_plugin.py
          ├── env_plugin.py
          ├── git_plugin.py
          ├── prompt_plugin.py
          ├── region_plugin.py
          ├── ssm_plugin.py
          ├── storage.py
          └── utils.py

Adding New Plugins

To add a new plugin:

  1. Create a new Python file in the toast/plugins directory
  2. Define a class that extends BasePlugin
  3. Implement the required methods (execute and optionally get_arguments)
  4. Set the name and help class variables

The plugin will be automatically discovered and loaded when the application starts.

from toast import ui
from toast.plugins.base_plugin import BasePlugin
import click

class MyPlugin(BasePlugin):
    name = "mycommand"
    help = "Description of my command"

    @classmethod
    def get_arguments(cls, func):
        # Optional: Define command arguments
        func = click.option("--option", "-o", help="An option for my command")(func)
        return func

    @classmethod
    def execute(cls, **kwargs):
        # Command implementation
        option = kwargs.get("option")
        if option:
            ui.result(f"Executing with option: {option}")
        else:
            ui.result("My custom command execution")

Benefits of the Plugin Architecture

  • Modularity: Each command is isolated in its own module
  • Extensibility: New commands can be added without modifying existing code
  • Maintainability: Code is organized into logical components
  • Testability: Plugins can be tested independently
  • Consistency: Common patterns are enforced through the base class
  • Discoverability: Commands are automatically found and registered