Aceptado
StackCode proporciona una herramienta CLI integral que necesita:
- Soportar múltiples comandos complejos con subcomandos
- Proporcionar prompts interactivos para orientación del usuario
- Manejar gestión de configuración
- Soportar internacionalización
- Proporcionar mensajes de ayuda y error consistentes
- Ser extensible para comandos futuros
Necesitábamos elegir:
- Framework/biblioteca CLI
- Estructura y organización de comandos
- Sistema de prompts interactivos
- Estrategia de manejo de errores
Usaremos Yargs como nuestro framework CLI primario con Inquirer para prompts interactivos:
- Usar Yargs para parseo de comandos, validación y generación de ayuda
- Implementar arquitectura basada en comandos con separación clara
- Soportar aliases y atajos para comandos comunes
- Proporcionar información comprensiva de ayuda y uso
- Each command is implemented as a separate module
- Commands follow a consistent interface pattern
- Support for subcommands where appropriate (e.g.,
git start,git finish) - Global options available across all commands
- Use Inquirer.js for complex user interactions
- Provide guided workflows for complex operations
- Validate user input at prompt level
- Support default values and smart suggestions
- Consistent error message formatting
- Localized error messages through i18n system
- Graceful handling of common error scenarios
- Debug mode for troubleshooting
- Developer Experience: Yargs provides excellent help generation and validation
- Consistency: Uniform command structure and behavior across all commands
- Extensibility: Easy to add new commands following established patterns
- User Guidance: Interactive prompts guide users through complex workflows
- Validation: Built-in argument validation and type checking
- Documentation: Auto-generated help text keeps documentation in sync
- Bundle Size: Yargs and Inquirer add significant dependencies
- Complexity: Learning curve for command configuration
- Performance: Startup time increased due to framework initialization
CLI Commands:
├── init # Project scaffolding
├── generate # File generation
├── commit # Conventional commits
├── git # Git workflow management
│ ├── start # Start feature branch
│ └── finish # Finish feature branch
├── release # Version management
├── validate # Commit validation
├── config # Configuration management
└── github # GitHub integration
Each command module exports a function that returns a Yargs command configuration:
export function getCommandName(): CommandModule {
return {
command: "command-name [args]",
describe: "Command description",
builder: (yargs) => {
return yargs.option("option", {
type: "string",
describe: "Option description",
});
},
handler: async (argv) => {
// Command implementation
},
};
}- Use prompts for complex multi-step workflows
- Provide sensible defaults based on project context
- Validate inputs and provide immediate feedback
- Support both interactive and non-interactive modes
- Support global and project-local configuration
- Configuration stored in standard locations (
~/.stackcode,.stackcode.json) - Command-line options override configuration files
- Environment variable support for CI/CD scenarios
- Pros: Lighter weight, simpler API
- Cons: Less feature-rich, manual help generation
- Pros: No dependencies, full control
- Cons: Significant development effort, poor developer experience
- Pros: More opinionated, additional features
- Cons: More complex, additional abstractions
- Each command should have comprehensive tests
- All user-facing strings must support internationalization
- Commands should validate inputs early and provide clear error messages
- Support both interactive and programmatic usage
- Use consistent error message formats
- Provide actionable error messages with suggestions
- Log detailed error information in debug mode
- Handle common scenarios gracefully (network issues, permission errors)
- Provide clear command descriptions and examples
- Document all options and their effects
- Include usage examples in help text
- Keep help text concise but comprehensive