|
| 1 | +# Contributing to Thalassa Cloud CLI |
| 2 | + |
| 3 | +Thank you for your interest in contributing to the Thalassa Cloud CLI! This document provides guidelines and instructions for contributing to the project. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +- [Getting Started](#getting-started) |
| 8 | +- [Development Setup](#development-setup) |
| 9 | +- [Project Structure](#project-structure) |
| 10 | +- [Development Workflow](#development-workflow) |
| 11 | +- [Code Style and Conventions](#code-style-and-conventions) |
| 12 | +- [Testing](#testing) |
| 13 | +- [Commit Messages](#commit-messages) |
| 14 | + |
| 15 | +## Getting Started |
| 16 | + |
| 17 | +1. **Fork the repository** on GitHub |
| 18 | +2. **Clone your fork** locally: |
| 19 | + ```bash |
| 20 | + git clone https://github.com/YOUR_USERNAME/cli.git |
| 21 | + cd cli |
| 22 | + ``` |
| 23 | +3. **Add the upstream remote**: |
| 24 | + ```bash |
| 25 | + git remote add upstream https://github.com/thalassa-cloud/cli.git |
| 26 | + ``` |
| 27 | + |
| 28 | +## Development Setup |
| 29 | + |
| 30 | +### Prerequisites |
| 31 | + |
| 32 | +- **Go 1.24 or later** - [Install Go](https://golang.org/doc/install) |
| 33 | +- **Make** - Usually pre-installed on Unix systems |
| 34 | +- **Git** - For version control |
| 35 | + |
| 36 | +### Building the Project |
| 37 | + |
| 38 | +```bash |
| 39 | +# Build the binary |
| 40 | +make build |
| 41 | + |
| 42 | +# The binary will be available at ./bin/tcloud |
| 43 | +./bin/tcloud --help |
| 44 | +``` |
| 45 | + |
| 46 | +### Running Tests |
| 47 | + |
| 48 | +```bash |
| 49 | +# Run unit tests |
| 50 | +make test |
| 51 | + |
| 52 | +# Run E2E tests (requires configuration) |
| 53 | +# NOTE: Creates real resources, which may cost money |
| 54 | +make test-e2e |
| 55 | +``` |
| 56 | + |
| 57 | +See the [Testing](#testing) section for more details. |
| 58 | + |
| 59 | +## Project Structure |
| 60 | + |
| 61 | +``` |
| 62 | +cli/ |
| 63 | +├── cmd/ # CLI commands organized by feature |
| 64 | +│ ├── context/ # Context management commands |
| 65 | +│ ├── iaas/ # IaaS-related commands |
| 66 | +│ ├── kubernetes/ # Kubernetes commands |
| 67 | +│ └── ... |
| 68 | +├── internal/ # Internal packages (not exported) |
| 69 | +│ ├── config/ # Configuration management |
| 70 | +│ ├── table/ # Table formatting utilities |
| 71 | +│ └── ... |
| 72 | +├── e2e/ # End-to-end tests |
| 73 | +├── docs/ # Documentation |
| 74 | +└── main.go # Application entry point |
| 75 | +``` |
| 76 | + |
| 77 | +### Command Organization |
| 78 | + |
| 79 | +Commands are organized in the `cmd/` directory following this structure: |
| 80 | +- Each top-level command has its own package (e.g., `cmd/kubernetes/`) |
| 81 | +- Subcommands are in the same package or subdirectories |
| 82 | +- Command files follow naming conventions: |
| 83 | + - `{command}.go` - Main command definition |
| 84 | + - `{subcommand}.go` - Subcommand implementation |
| 85 | + |
| 86 | +## Development Workflow |
| 87 | + |
| 88 | +1. **Create a feature branch**: |
| 89 | + ```bash |
| 90 | + git checkout -b feature/your-feature-name |
| 91 | + ``` |
| 92 | + |
| 93 | +2. **Make your changes** following the code style guidelines |
| 94 | + |
| 95 | +3. **Write tests** for your changes (see [Testing](#testing)) |
| 96 | + |
| 97 | +4. **Run tests** to ensure everything passes: |
| 98 | + ```bash |
| 99 | + make test |
| 100 | + ``` |
| 101 | + |
| 102 | +5. **Commit your changes** using semantic commit messages (see [Commit Messages](#commit-messages)) |
| 103 | + |
| 104 | +6. **Push to your fork**: |
| 105 | + ```bash |
| 106 | + git push origin feature/your-feature-name |
| 107 | + ``` |
| 108 | + |
| 109 | +7. **Create a Pull Request** on GitHub |
| 110 | + |
| 111 | +## Code Style and Conventions |
| 112 | + |
| 113 | +### Go Code Style |
| 114 | + |
| 115 | +- Follow standard Go formatting: `go fmt ./...` |
| 116 | +- Follow [Effective Go](https://golang.org/doc/effective_go) guidelines |
| 117 | +- Use `golangci-lint` or similar tools for linting (if configured) |
| 118 | + |
| 119 | +## Testing |
| 120 | + |
| 121 | +### Unit Tests |
| 122 | + |
| 123 | +Unit tests are located alongside the code they test (e.g., `labels_test.go` in the `labels` package). |
| 124 | + |
| 125 | +- Use table-driven tests for multiple test cases |
| 126 | +- Use the `testify` package for assertions |
| 127 | +- Keep tests simple and focused on one behavior |
| 128 | + |
| 129 | +**Example:** |
| 130 | +```go |
| 131 | +func TestParseLabelSelector(t *testing.T) { |
| 132 | + tests := []struct { |
| 133 | + name string |
| 134 | + selector string |
| 135 | + expected map[string]string |
| 136 | + }{ |
| 137 | + { |
| 138 | + name: "single label", |
| 139 | + selector: "key1=value1", |
| 140 | + expected: map[string]string{"key1": "value1"}, |
| 141 | + }, |
| 142 | + // ... more test cases |
| 143 | + } |
| 144 | + |
| 145 | + for _, tt := range tests { |
| 146 | + t.Run(tt.name, func(t *testing.T) { |
| 147 | + result := ParseLabelSelector(tt.selector) |
| 148 | + assert.Equal(t, tt.expected, result) |
| 149 | + }) |
| 150 | + } |
| 151 | +} |
| 152 | +``` |
| 153 | + |
| 154 | +**Running Unit Tests:** |
| 155 | +```bash |
| 156 | +# Run all unit tests |
| 157 | +make test |
| 158 | + |
| 159 | +# Run tests for a specific package |
| 160 | +go test ./internal/labels/... |
| 161 | + |
| 162 | +# Run tests with verbose output |
| 163 | +go test -v ./internal/labels/... |
| 164 | +``` |
| 165 | + |
| 166 | +### E2E Tests |
| 167 | + |
| 168 | +End-to-end tests are located in the `e2e/` directory and test the actual CLI binary against a real API. |
| 169 | + |
| 170 | +**Setup:** |
| 171 | +1. Build the binary: `make build` |
| 172 | +2. Configure environment variables (see `e2e/README.md` for details): |
| 173 | + ```bash |
| 174 | + export TCLOUD_E2E_API_ENDPOINT="https://api.thalassa.cloud" |
| 175 | + export TCLOUD_E2E_PERSONAL_ACCESS_TOKEN="your-token" |
| 176 | + ``` |
| 177 | + |
| 178 | +**Running E2E Tests:** |
| 179 | +```bash |
| 180 | +# Run all E2E tests |
| 181 | +make test-e2e |
| 182 | + |
| 183 | +# Run specific E2E test |
| 184 | +go test ./e2e/... -v -run TestVersion |
| 185 | + |
| 186 | +# Run with custom binary path |
| 187 | +TCLOUD_E2E_BINARY_PATH=/path/to/tcloud go test ./e2e/... -v |
| 188 | +``` |
| 189 | + |
| 190 | +For more details, see `e2e/README.md`. |
| 191 | + |
| 192 | +## Commit Messages |
| 193 | + |
| 194 | +We follow **semantic commit message** conventions. Commit messages should be clear, descriptive, and follow this format: |
| 195 | + |
| 196 | +``` |
| 197 | +<type>(<scope>): <subject> |
| 198 | +
|
| 199 | +<body> |
| 200 | +
|
| 201 | +<footer> |
| 202 | +``` |
| 203 | + |
| 204 | +### Types |
| 205 | + |
| 206 | +- `feat`: New feature |
| 207 | +- `fix`: Bug fix |
| 208 | +- `docs`: Documentation changes |
| 209 | +- `test`: Adding or updating tests |
| 210 | +- `refactor`: Code refactoring (no behavior change) |
| 211 | +- `style`: Code style changes (formatting, etc.) |
| 212 | +- `chore`: Maintenance tasks |
| 213 | +- `perf`: Performance improvements |
| 214 | + |
| 215 | +### Examples |
| 216 | + |
| 217 | +``` |
| 218 | +feat(vpcs): add support for label selectors in list command |
| 219 | +
|
| 220 | +This allows users to filter VPCs by labels when listing them, |
| 221 | +improving usability for managing large numbers of resources. |
| 222 | +
|
| 223 | +Closes #123 |
| 224 | +``` |
| 225 | + |
| 226 | +``` |
| 227 | +fix(auth): handle expired tokens gracefully |
| 228 | +
|
| 229 | +Previously, expired tokens would cause a panic. Now they are |
| 230 | +handled with a clear error message prompting the user to re-authenticate. |
| 231 | +``` |
| 232 | + |
| 233 | +``` |
| 234 | +test(e2e): add E2E tests for me organisations command |
| 235 | +
|
| 236 | +Adds comprehensive E2E tests covering all flags and output formats |
| 237 | +for the me organisations command. |
| 238 | +``` |
| 239 | + |
| 240 | +### Guidelines |
| 241 | + |
| 242 | +- Use imperative mood ("add" not "added" or "adds") |
| 243 | +- Keep the subject line under 50 characters |
| 244 | +- Capitalize the first letter of the subject |
| 245 | +- Don't end the subject with a period |
| 246 | +- Use the body to explain *what* and *why* (not *how*) |
| 247 | +- Reference issues and PRs in the footer |
0 commit comments