Architecture Overview
mesheryctl is a standalone Go application that communicates with:- Meshery Server APIs – REST and GraphQL endpoints
- Docker – For local container management
- Kubernetes – For cluster deployments and management
- Local filesystem – For configuration and context management
Repository Structure
The CLI code is located in the/mesheryctl directory:
Development Workflow
Building mesheryctl
Build the binary:mesheryctl binary in the mesheryctl/ directory.
Verify the build:
Running mesheryctl
Basic commands:Project Structure
mesheryctl follows the Cobra framework structure: Root command:mesheryctl/cmd/root.go
cmd/system/, cmd/pattern/)
Code Style and Best Practices
Go Code Style
Follow the same Go code style as the Meshery Server:- Use
gofmtandgoimportsfor formatting - Follow Go naming conventions
- Use meaningful variable and function names
- Add comments for exported functions
Command Structure
Each command follows this structure:Error Handling
Use descriptive error messages:Output Formatting
Support multiple output formats:Testing
Unit Tests
Run unit tests:Integration Tests
Run integration tests:Writing Tests
Example unit test:Common Tasks
Adding a New Command
- Create command file:
- Register command:
- Add to root command:
Adding Command Flags
String flag:Making API Calls
REST API call with HTTP client:Configuration Management
mesheryctl uses Viper for configuration management. Read configuration:Working with Contexts
mesheryctl supports multiple contexts (similar to kubectl). List contexts:Documentation
Generating CLI Documentation
mesheryctl can auto-generate markdown documentation from command definitions. Generate docs:docs/ directory.
Command Documentation Format
Ensure commands have proper documentation:Integration with Meshery Server
API Endpoints
mesheryctl communicates with these Meshery Server endpoints:GET /api/system/version– Get server versionGET /api/workspaces– List workspacesPOST /api/pattern/deploy– Deploy a patternGET /api/mesh/adapters– List available adapters
Authentication
mesheryctl uses token-based authentication:Platform Support
mesheryctl supports multiple deployment platforms:- Docker – Local container deployment
- Kubernetes – Kubernetes cluster deployment
- Docker Compose – Multi-container deployment
Debugging
Enable Verbose Output
Debug Logging
Add debug logs in code:Environment Variables
Building for Release
Cross-Platform Builds
Build for multiple platforms:Version Information
Version information is set during build:Common Commands Reference
System Commands
Pattern Commands
Mesh Commands
App Commands
Next Steps
Testing Guide
Learn how to test CLI changes
Code Style
Review Go code style guidelines
Server Development
Contribute to the backend
UI Development
Contribute to the frontend