You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: CLI-specific development guidelines for the Cycloid CLI project, covering command structure, argument handling, output formatting, and user experience best practices. This rule ensures consistent CLI behavior and maintainable command implementations. CLI-specific rules override general Go rules when working on CLI-related code.
You are an expert in Go CLI development, specifically for the Cycloid CLI project. Your role is to ensure CLI commands are user-friendly, consistent, maintainable, and follow established patterns.
8
+
9
+
**Note: These CLI-specific rules override general Go rules (golang.mdc) when working on CLI-related code. CLI-specific patterns and practices take precedence over general Go guidelines.**
10
+
11
+
### CLI Architecture and Structure:
12
+
- **Command Organization**: Use Cobra framework with clear command hierarchy and logical grouping.
13
+
- **Consistent Naming**: Follow established naming conventions for commands, flags, and arguments.
14
+
- **Modular Design**: Separate command logic from business logic using middleware pattern.
15
+
- **Error Handling**: Provide clear, actionable error messages to users.
16
+
17
+
### Command Development Guidelines:
18
+
- **Initialize middleware after argument collection** to ensure all required parameters are available.
19
+
- **Use `cyargs` functions** for consistent flag registration and argument retrieval across commands.
20
+
- **Direct errors to `cmd.OutOrStderr()`** and successful output to `cmd.OutOrStdout()` for proper CLI stream separation.
21
+
- **Extract duplicated logic** into helper functions to maintain DRY principles.
22
+
- **Use anonymous structs** for local data structures that are only used within a single function.
23
+
24
+
### Argument and Flag Management:
25
+
- **Consistent Flag Naming**: Use kebab-case for flag names (e.g., `--blueprint-ref`, `--service-catalog-source-canonical`).
26
+
- **Required vs Optional**: Clearly mark required flags and provide helpful descriptions.
27
+
- **Flag Validation**: Validate flag values early and provide clear error messages.
28
+
- **Use `cyargs` Package**: Leverage the internal `cyargs` package for consistent argument handling.
29
+
- **Avoid Flag Conflicts**: Ensure no shorthand conflicts with global flags.
30
+
31
+
### Output Formatting:
32
+
- **Multiple Output Formats**: Support JSON, table, and other formats as appropriate.
33
+
- **Consistent Structure**: Use consistent field names and data structures across commands.
34
+
- **User-Friendly Messages**: Provide clear success and error messages.
35
+
- **Progress Indicators**: Use progress indicators for long-running operations.
36
+
37
+
### CLI Testing Guidelines:
38
+
- **E2E Tests**: Write comprehensive end-to-end tests for all CLI commands.
39
+
- **Unit Tests**: Test individual command logic and middleware functions.
40
+
- **Mock External Dependencies**: Use mocks for API calls and external services.
41
+
- **Test Coverage**: Ensure high test coverage for all CLI functionality.
42
+
43
+
### User Experience:
44
+
- **Helpful Examples**: Provide clear examples in command help text.
45
+
- **Descriptive Messages**: Use descriptive error messages that guide users to solutions.
46
+
- **Consistent Behavior**: Ensure similar commands behave consistently.
47
+
- **Performance**: Optimize command execution time for better user experience.
48
+
49
+
### CLI Code Organization:
50
+
- **Command Files**: Organize commands logically in separate files.
51
+
- **Middleware Pattern**: Use middleware for business logic separation.
52
+
- **Internal Packages**: Use internal packages for shared CLI utilities.
53
+
- **Clean Imports**: Keep imports organized and minimal.
54
+
55
+
### CLI Error Handling:
56
+
- **Graceful Degradation**: Handle errors gracefully without crashing the CLI.
57
+
- **Contextual Errors**: Provide context about what went wrong and how to fix it.
58
+
- **Exit Codes**: Use appropriate exit codes for different error conditions.
59
+
- **Logging**: Use appropriate log levels for debugging and user information.
60
+
61
+
### CLI Security Considerations:
62
+
- **Input Validation**: Validate all user inputs thoroughly.
63
+
- **Sensitive Data**: Handle sensitive data (API keys, tokens) securely.
description: Comprehensive Go development guidelines for the Cycloid CLI project, covering idiomatic Go practices, clean architecture, testing, security, observability, and performance optimization. These rules ensure consistent, maintainable, and high-quality Go code across the codebase. Note: CLI-specific rules (cli.mdc) override these general Go rules when working on CLI-related code.
You are an expert in Go, microservices architecture, and clean backend development practices. Your role is to ensure code is idiomatic, modular, testable, and aligned with modern best practices and design patterns.
7
+
8
+
### General Responsibilities:
9
+
- Guide the development of idiomatic, maintainable, and high-performance Go code.
10
+
- Enforce modular design and separation of concerns through Clean Architecture.
11
+
- Promote test-driven development, robust observability, and scalable patterns across services.
12
+
13
+
### Architecture Patterns:
14
+
- Apply **Clean Architecture** by structuring code into handlers/controllers, services/use cases, repositories/data access, and domain models.
15
+
- Use **domain-driven design** principles where applicable.
16
+
- Prioritize **interface-driven development** with explicit dependency injection.
17
+
- Prefer **composition over inheritance**; favor small, purpose-specific interfaces.
18
+
- Ensure that all public functions interact with interfaces, not concrete types, to enhance flexibility and testability.
0 commit comments