|
| 1 | +# Contributing to Zut |
| 2 | + |
| 3 | +Thank you for your interest in contributing to Zut! This document provides guidelines and instructions for contributing. |
| 4 | + |
| 5 | +## Development Setup |
| 6 | + |
| 7 | +### Prerequisites |
| 8 | + |
| 9 | +- Go 1.23.6 or higher |
| 10 | +- Git |
| 11 | + |
| 12 | +### Getting Started |
| 13 | + |
| 14 | +1. Fork the repository |
| 15 | +2. Clone your fork: |
| 16 | + ```bash |
| 17 | + git clone https://github.com/yourusername/zut.git |
| 18 | + cd zut |
| 19 | + ``` |
| 20 | + |
| 21 | +3. Install dependencies: |
| 22 | + ```bash |
| 23 | + go mod download |
| 24 | + ``` |
| 25 | + |
| 26 | +4. Build the project: |
| 27 | + ```bash |
| 28 | + make build |
| 29 | + # or |
| 30 | + go build -o zut . |
| 31 | + ``` |
| 32 | + |
| 33 | +5. Run tests: |
| 34 | + ```bash |
| 35 | + make test |
| 36 | + # or |
| 37 | + go test ./... |
| 38 | + ``` |
| 39 | + |
| 40 | +## Project Structure |
| 41 | + |
| 42 | +``` |
| 43 | +zut/ |
| 44 | +├── cmd/ # CLI command implementations |
| 45 | +│ ├── root.go # Root command and CLI setup |
| 46 | +│ ├── add.go # Add command |
| 47 | +│ ├── list.go # List command |
| 48 | +│ ├── delete.go # Delete command |
| 49 | +│ ├── edit.go # Edit command |
| 50 | +│ ├── run.go # Run command |
| 51 | +│ └── find.go # Find/search command |
| 52 | +├── internal/core/ # Core business logic |
| 53 | +│ ├── core.go # Command management |
| 54 | +│ └── core_test.go # Core tests |
| 55 | +├── pkg/storage/ # Data persistence layer |
| 56 | +│ ├── storage.go # Storage implementation |
| 57 | +│ └── storage_test.go # Storage tests |
| 58 | +├── main.go # Application entry point |
| 59 | +├── go.mod # Go module definition |
| 60 | +├── Makefile # Build automation |
| 61 | +├── README.md # Main documentation |
| 62 | +├── ROADMAP.md # Project roadmap |
| 63 | +├── EXAMPLES.md # Usage examples |
| 64 | +└── CONTRIBUTING.md # This file |
| 65 | +``` |
| 66 | + |
| 67 | +## Development Workflow |
| 68 | + |
| 69 | +### Making Changes |
| 70 | + |
| 71 | +1. Create a new branch: |
| 72 | + ```bash |
| 73 | + git checkout -b feature/your-feature-name |
| 74 | + ``` |
| 75 | + |
| 76 | +2. Make your changes |
| 77 | + |
| 78 | +3. Run tests: |
| 79 | + ```bash |
| 80 | + make test |
| 81 | + ``` |
| 82 | + |
| 83 | +4. Format your code: |
| 84 | + ```bash |
| 85 | + make fmt |
| 86 | + ``` |
| 87 | + |
| 88 | +5. Commit your changes: |
| 89 | + ```bash |
| 90 | + git commit -am "Add feature: description" |
| 91 | + ``` |
| 92 | + |
| 93 | +6. Push to your fork: |
| 94 | + ```bash |
| 95 | + git push origin feature/your-feature-name |
| 96 | + ``` |
| 97 | + |
| 98 | +7. Create a Pull Request |
| 99 | + |
| 100 | +### Commit Message Guidelines |
| 101 | + |
| 102 | +- Use present tense ("Add feature" not "Added feature") |
| 103 | +- Use imperative mood ("Move cursor to..." not "Moves cursor to...") |
| 104 | +- Start with a capital letter |
| 105 | +- Keep first line under 72 characters |
| 106 | +- Reference issues and pull requests when relevant |
| 107 | + |
| 108 | +Examples: |
| 109 | +``` |
| 110 | +Add search functionality to list command |
| 111 | +Fix bug in command deletion |
| 112 | +Update README with installation instructions |
| 113 | +Refactor storage layer for better error handling |
| 114 | +``` |
| 115 | + |
| 116 | +## Testing |
| 117 | + |
| 118 | +### Running Tests |
| 119 | + |
| 120 | +```bash |
| 121 | +# Run all tests |
| 122 | +make test |
| 123 | + |
| 124 | +# Run tests with coverage |
| 125 | +make test-coverage |
| 126 | + |
| 127 | +# Run tests verbosely |
| 128 | +go test ./... -v |
| 129 | + |
| 130 | +# Run specific package tests |
| 131 | +go test ./pkg/storage -v |
| 132 | +go test ./internal/core -v |
| 133 | +``` |
| 134 | + |
| 135 | +### Writing Tests |
| 136 | + |
| 137 | +- Place test files next to the code they test (e.g., `storage.go` → `storage_test.go`) |
| 138 | +- Use table-driven tests when testing multiple scenarios |
| 139 | +- Use meaningful test names that describe what is being tested |
| 140 | +- Test both success and error cases |
| 141 | +- Aim for high test coverage (>80%) |
| 142 | + |
| 143 | +Example test structure: |
| 144 | +```go |
| 145 | +func TestFeatureName(t *testing.T) { |
| 146 | + // Setup |
| 147 | + manager := setupTestManager(t) |
| 148 | + |
| 149 | + // Execute |
| 150 | + err := manager.SomeMethod() |
| 151 | + |
| 152 | + // Verify |
| 153 | + if err != nil { |
| 154 | + t.Fatalf("SomeMethod() failed: %v", err) |
| 155 | + } |
| 156 | +} |
| 157 | +``` |
| 158 | + |
| 159 | +## Code Style |
| 160 | + |
| 161 | +### Go Conventions |
| 162 | + |
| 163 | +- Follow standard Go formatting (use `gofmt` or `make fmt`) |
| 164 | +- Use meaningful variable and function names |
| 165 | +- Keep functions small and focused |
| 166 | +- Add comments for exported functions and types |
| 167 | +- Handle errors appropriately |
| 168 | +- Use `go vet` to catch common mistakes |
| 169 | + |
| 170 | +### Package Organization |
| 171 | + |
| 172 | +- `cmd/` - CLI command implementations (uses Cobra) |
| 173 | +- `internal/core/` - Business logic (should not import cmd/) |
| 174 | +- `pkg/storage/` - Reusable storage utilities |
| 175 | + |
| 176 | +### Error Handling |
| 177 | + |
| 178 | +```go |
| 179 | +// Good: Wrap errors with context |
| 180 | +if err := doSomething(); err != nil { |
| 181 | + return fmt.Errorf("failed to do something: %w", err) |
| 182 | +} |
| 183 | + |
| 184 | +// Good: Check errors immediately |
| 185 | +result, err := fetchData() |
| 186 | +if err != nil { |
| 187 | + return err |
| 188 | +} |
| 189 | + |
| 190 | +// Bad: Ignoring errors |
| 191 | +result, _ := fetchData() |
| 192 | +``` |
| 193 | + |
| 194 | +## Adding New Features |
| 195 | + |
| 196 | +### Adding a New Command |
| 197 | + |
| 198 | +1. Create a new file in `cmd/` (e.g., `cmd/newcommand.go`) |
| 199 | +2. Implement the command using Cobra: |
| 200 | + ```go |
| 201 | + func NewMyCommand() *cobra.Command { |
| 202 | + cmd := &cobra.Command{ |
| 203 | + Use: "mycommand", |
| 204 | + Short: "Brief description", |
| 205 | + Long: "Detailed description", |
| 206 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 207 | + // Implementation |
| 208 | + return nil |
| 209 | + }, |
| 210 | + } |
| 211 | + return cmd |
| 212 | + } |
| 213 | + ``` |
| 214 | + |
| 215 | +3. Register the command in `cmd/root.go`: |
| 216 | + ```go |
| 217 | + cmd.AddCommand(NewMyCommand()) |
| 218 | + ``` |
| 219 | + |
| 220 | +4. Add tests in `cmd/` if needed |
| 221 | +5. Update README.md with usage examples |
| 222 | + |
| 223 | +### Adding Core Functionality |
| 224 | + |
| 225 | +1. Add methods to the `Manager` struct in `internal/core/core.go` |
| 226 | +2. Write comprehensive unit tests in `internal/core/core_test.go` |
| 227 | +3. Ensure tests achieve good coverage |
| 228 | +4. Update documentation |
| 229 | + |
| 230 | +### Modifying Storage |
| 231 | + |
| 232 | +1. Update `pkg/storage/storage.go` |
| 233 | +2. Add/update tests in `pkg/storage/storage_test.go` |
| 234 | +3. Consider backward compatibility with existing data files |
| 235 | +4. Test migration paths if changing data format |
| 236 | + |
| 237 | +## Performance Considerations |
| 238 | + |
| 239 | +- Commands should execute in <100ms for typical use cases |
| 240 | +- Use in-memory maps for fast lookups (O(1) complexity) |
| 241 | +- Minimize file I/O operations |
| 242 | +- Profile code if adding complex features: |
| 243 | + ```bash |
| 244 | + go test -cpuprofile=cpu.prof -bench=. |
| 245 | + go tool pprof cpu.prof |
| 246 | + ``` |
| 247 | + |
| 248 | +## Documentation |
| 249 | + |
| 250 | +When adding features, update: |
| 251 | + |
| 252 | +- `README.md` - For user-facing features |
| 253 | +- `EXAMPLES.md` - Add practical examples |
| 254 | +- Code comments - For exported functions |
| 255 | +- `ROADMAP.md` - Mark completed items, add new goals |
| 256 | + |
| 257 | +## Release Process |
| 258 | + |
| 259 | +1. Update version in relevant files |
| 260 | +2. Update CHANGELOG (if exists) |
| 261 | +3. Create a git tag: |
| 262 | + ```bash |
| 263 | + git tag -a v1.0.0 -m "Release version 1.0.0" |
| 264 | + git push origin v1.0.0 |
| 265 | + ``` |
| 266 | + |
| 267 | +4. Build release binaries: |
| 268 | + ```bash |
| 269 | + make build-all |
| 270 | + ``` |
| 271 | + |
| 272 | +5. Create GitHub release with binaries |
| 273 | + |
| 274 | +## Getting Help |
| 275 | + |
| 276 | +- Check existing issues and pull requests |
| 277 | +- Read the ROADMAP.md for project direction |
| 278 | +- Ask questions in issue comments |
| 279 | +- Reach out to maintainers |
| 280 | + |
| 281 | +## Code of Conduct |
| 282 | + |
| 283 | +- Be respectful and inclusive |
| 284 | +- Provide constructive feedback |
| 285 | +- Focus on what is best for the project |
| 286 | +- Show empathy towards other contributors |
| 287 | + |
| 288 | +## License |
| 289 | + |
| 290 | +By contributing, you agree that your contributions will be licensed under the same license as the project (MIT License). |
| 291 | + |
| 292 | +--- |
| 293 | + |
| 294 | +Thank you for contributing to Zut! 🚀 |
0 commit comments