Toast-cli is a Python-based CLI tool for AWS, Kubernetes, and Git operations. It uses a plugin-based architecture for extensibility, allowing new commands to be added without modifying existing code.
toast-cli/
├── setup.py # Package setup script
├── setup.cfg # Package configuration
├── 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 (GNU GPL v3.0)
├── docs/ # Documentation website 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 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
├── region_plugin.py
└── utils.py
- Dynamically discovers and loads plugins
- Registers plugin commands with Click
- Runs the CLI with all discovered commands
- Provides core commands like
version
- Enables running as a module with
python -m toast
- Contains helper functions and UI elements
- Handles version information retrieval
- Provides custom Click classes for enhanced help display
The plugin system uses Python's importlib
and pkgutil
modules for dynamic loading at runtime.
-
BasePlugin (
plugins/base_plugin.py
)- Abstract base class for all plugins
- Defines interface with required methods:
register()
: Registers with the CLIget_arguments()
: Defines command argumentsexecute()
: Contains command implementation
-
Utilities (
plugins/utils.py
)- Common utility functions for plugins
- Interactive selection using fzf
- Subprocess execution and error handling
Each plugin:
- Inherits from
BasePlugin
- Defines unique
name
andhelp
text - Implements
execute()
method - Optionally overrides
get_arguments()
- Scan plugins directory for Python modules
- Import each module
- Find classes extending
BasePlugin
- Register valid plugins with the CLI
- Handle command execution via Click
Command | Description |
---|---|
version | Display the current version |
am | Show AWS caller identity |
cdw | Navigate to workspace directories |
ctx | Manage Kubernetes contexts |
dot | Manage .env.local files with AWS SSM integration |
env | Manage AWS profiles |
git | Manage Git repositories |
region | Set AWS region |
- Shows current AWS identity using
aws sts get-caller-identity
- Formats JSON output with
rich
- Searches directories in
~/workspace
- Uses fzf for interactive selection
- Outputs selected path for shell navigation
- Manages Kubernetes contexts
- Integrates with EKS for cluster discovery
- Handles context switching and deletion
- Manages .env.local files with AWS SSM
- Uploads/downloads environment variables as SecureString
- Validates workspace path structure
- Manages AWS profiles from credentials file
- Sets selected profile as default
- Verifies identity after switching
- Displays and sets AWS regions
- Updates AWS CLI configuration
- Handles Git repository operations
- Supports cloning, branch creation, pulling
- Validates repository paths
- Click: Command-line interface creation
- importlib/pkgutil: Dynamic module discovery
- External tools:
- fzf: Interactive selection
- aws-cli: AWS operations
- kubectl: Kubernetes operations
- Python packages:
- rich: Terminal formatting
- Create a Python file in
toast/plugins/
- Define a class extending
BasePlugin
- Implement
execute()
method - Set
name
andhelp
class variables
The plugin will be automatically discovered and loaded.
- Modularity: Isolated command implementations
- Extensibility: Add commands without modifying core code
- Maintainability: Organized, logical components
- Consistency: Common patterns through base class
# Install from PyPI
pip install toast-cli
# Install in development mode
pip install -e .
# Install from GitHub
pip install git+https://github.com/opspresso/toast-cli.git
The package is available on PyPI at https://pypi.org/project/toast-cli/
To build distribution packages:
# Install build requirements
pip install build
# Build source and wheel distributions
python -m build
# This will create:
# - dist/toast-cli-X.Y.Z.tar.gz (source distribution)
# - dist/toast_cli-X.Y.Z-py3-none-any.whl (wheel distribution)
To publish the package to PyPI:
# Install twine
pip install twine
# Upload to PyPI
twine upload dist/*