Cursor rule
.cursor/rules/commands.mdcGuidelines for implementing CLI commands using Commander.js
Cursor rules
Quality
62/100
Scores the file, not the repository.Length
939 words
9 headings · 10 code blocksRepository
192
— · pushed 309 days agoLast changed
3 days ago
First indexed 3 days ago.1234567# Command-Line Interface Implementation Guidelines89## Command Structure Standards1011- **Basic Command Template**:12```javascript13 // ✅ DO: Follow this structure for all commands14 programInstance15 .command('command-name')16 .description('Clear, concise description of what the command does')17 .option('-s, --short-option <value>', 'Option description', 'default value')18 .option('--long-option <value>', 'Option description')19 .action(async (options) => {20 // Command implementation21 });22```2324- **Command Handler Organization**:25 - ✅ DO: Keep action handlers concise and focused26 - ✅ DO: Extract core functionality to appropriate modules27 - ✅ DO: Include validation for required parameters28 - ❌ DON'T: Implement business logic in command handlers2930## Option Naming Conventions3132- **Command Names**:33 - ✅ DO: Use kebab-case for command names (`analyze-complexity`)34 - ❌ DON'T: Use camelCase for command names (`analyzeComplexity`)35 - ✅ DO: Use descriptive, action-oriented names3637- **Option Names**:38 - ✅ DO: Use kebab-case for long-form option names (`--output-format`)39 - ✅ DO: Provide single-letter shortcuts when appropriate (`-f, --file`)40 - ✅ DO: Use consistent option names across similar commands41 - ❌ DON'T: Use different names for the same concept (`--file` in one command, `--path` in another)4243```javascript44 // ✅ DO: Use consistent option naming45 .option('-f, --file <path>', 'Path to the tasks file', 'tasks/tasks.json')46 .option('-o, --output <dir>', 'Output directory', 'tasks')4748 // ❌ DON'T: Use inconsistent naming49 .option('-f, --file <path>', 'Path to the tasks file')50 .option('-p, --path <dir>', 'Output directory') // Should be --output51```5253 > **Note**: Although options are defined with kebab-case (`--num-tasks`), Commander.js stores them internally as camelCase properties. Access them in code as `options.numTasks`, not `options['num-tasks']`.5455## Input Validation5657- **Required Parameters**:58 - ✅ DO: Check that required parameters are provided59 - ✅ DO: Provide clear error messages when parameters are missing60 - ✅ DO: Use early returns with process.exit(1) for validation failures6162```javascript63 // ✅ DO: Validate required parameters early64 if (!prompt) {65 console.error(chalk.red('Error: --prompt parameter is required. Please provide a task description.'));66 process.exit(1);67 }68```6970- **Parameter Type Conversion**:71 - ✅ DO: Convert string inputs to appropriate types (numbers, booleans)72 - ✅ DO: Handle conversion errors gracefully7374```javascript75 // ✅ DO: Parse numeric parameters properly76 const fromId = parseInt(options.from, 10);77 if (isNaN(fromId)) {78 console.error(chalk.red('Error: --from must be a valid number'));79 process.exit(1);80 }81```8283## User Feedback8485- **Operation Status**:86 - ✅ DO: Provide clear feedback about the operation being performed87 - ✅ DO: Display success or error messages after completion88 - ✅ DO: Use colored output to distinguish between different message types8990```javascript91 // ✅ DO: Show operation status92 console.log(chalk.blue(`Parsing PRD file: ${file}`));93 console.log(chalk.blue(`Generating ${numTasks} tasks...`));9495 try {96 await parsePRD(file, outputPath, numTasks);97 console.log(chalk.green('Successfully generated tasks from PRD'));98 } catch (error) {99 console.error(chalk.red(`Error: ${error.message}`));100 process.exit(1);101 }102```103104## Command Registration105106- **Command Grouping**:107 - ✅ DO: Group related commands together in the code108 - ✅ DO: Add related commands in a logical order109 - ✅ DO: Use comments to delineate command groups110111- **Command Export**:112 - ✅ DO: Export the registerCommands function113 - ✅ DO: Keep the CLI setup code clean and maintainable114115```javascript116 // ✅ DO: Follow this export pattern117 export {118 registerCommands,119 setupCLI,120 runCLI121 };122```123124## Error Handling125126- **Exception Management**:127 - ✅ DO: Wrap async operations in try/catch blocks128 - ✅ DO: Display user-friendly error messages129 - ✅ DO: Include detailed error information in debug mode130131```javascript132 // ✅ DO: Handle errors properly133 try {134 // Command implementation135 } catch (error) {136 console.error(chalk.red(`Error: ${error.message}`));137138 if (CONFIG.debug) {139 console.error(error);140 }141142 process.exit(1);143 }144```145146## Integration with Other Modules147148- **Import Organization**:149 - ✅ DO: Group imports by module/functionality150 - ✅ DO: Import only what's needed, not entire modules151 - ❌ DON'T: Create circular dependencies152153```javascript154 // ✅ DO: Organize imports by module155 import { program } from 'commander';156 import path from 'path';157 import chalk from 'chalk';158159 import { CONFIG, log, readJSON } from './utils.js';160 import { displayBanner, displayHelp } from './ui.js';161 import { parsePRD, listTasks } from './task-manager.js';162 import { addDependency } from './dependency-manager.js';163```164165## Subtask Management Commands166167- **Add Subtask Command Structure**:168```javascript169 // ✅ DO: Follow this structure for adding subtasks170 programInstance171 .command('add-subtask')172 .description('Add a new subtask to a parent task or convert an existing task to a subtask')173 .option('-f, --file <path>', 'Path to the tasks file', 'tasks/tasks.json')174 .option('-p, --parent <id>', 'ID of the parent task (required)')175 .option('-e, --existing <id>', 'ID of an existing task to convert to a subtask')176 .option('-t, --title <title>', 'Title for the new subtask (when not converting)')177 .option('-d, --description <description>', 'Description for the new subtask (when not converting)')178 .option('--details <details>', 'Implementation details for the new subtask (when not converting)')179 .option('--dependencies <ids>', 'Comma-separated list of subtask IDs this subtask depends on')180 .option('--status <status>', 'Initial status for the subtask', 'pending')181 .action(async (options) => {182 // Validate required parameters183 if (!options.parent) {184 console.error(chalk.red('Error: --parent parameter is required'));185 process.exit(1);186 }187188 // Validate that either existing task ID or title is provided189 if (!options.existing && !options.title) {190 console.error(chalk.red('Error: Either --existing or --title must be provided'));191 process.exit(1);192 }193194 try {195 // Implementation196 } catch (error) {197 // Error handling198 }199 });200```201202- **Remove Subtask Command Structure**:203```javascript204 // ✅ DO: Follow this structure for removing subtasks205 programInstance206 .command('remove-subtask')207 .description('Remove a subtask from its parent task, optionally converting it to a standalone task')208 .option('-f, --file <path>', 'Path to the tasks file', 'tasks/tasks.json')209 .option('-i, --id <id>', 'ID of the subtask to remove in format "parentId.subtaskId" (required)')210 .option('-c, --convert', 'Convert the subtask to a standalone task')211 .action(async (options) => {212 // Validate required parameters213 if (!options.id) {214 console.error(chalk.red('Error: --id parameter is required'));215 process.exit(1);216 }217218 // Validate subtask ID format219 if (!options.id.includes('.')) {220 console.error(chalk.red('Error: Subtask ID must be in format "parentId.subtaskId"'));221 process.exit(1);222 }223224 try {225 // Implementation226 } catch (error) {227 // Error handling228 }229 });230```231232Refer to [`commands.js`](mdc:scripts/modules/commands.js) for implementation examples and [`new_features.mdc`](mdc:.cursor/rules/new_features.mdc) for integration guidelines.
Also in skindhu/AI-TASK-MANAGER
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| skindhu/AI-TASK-MANAGER.cursor/rules/ui.mdc · 192 | Cursor rules | ui | 62/100 | 3 days ago | |
| skindhu/AI-TASK-MANAGER.cursor/rules/architecture.mdc · 192 | Cursor rules | testarchtesting-strategy | 42/100 | 3 days ago | |
| skindhu/AI-TASK-MANAGER.cursor/rules/cursor_rules.mdc · 192 | Cursor rules | no sections | 36/100 | 3 days ago | |
| skindhu/AI-TASK-MANAGER.cursor/rules/dependencies.mdc · 192 | Cursor rules | arch | 66/100 | 3 days ago | |
| skindhu/AI-TASK-MANAGER.cursor/rules/dev_workflow.mdc · 192 | Cursor rules | setup | 52/100 | 3 days ago | |
| skindhu/AI-TASK-MANAGER.cursor/rules/new_features.mdc · 192 | Cursor rules | testtesting-strategydocs | 65/100 | 3 days ago | |
| skindhu/AI-TASK-MANAGER.cursor/rules/self_improve.mdc · 192 | Cursor rules | no sections | 36/100 | 3 days ago | |
| skindhu/AI-TASK-MANAGER.cursor/rules/tasks.mdc · 192 | Cursor rules | arch | 70/100 | 3 days ago | |
| skindhu/AI-TASK-MANAGER.cursor/rules/tests.mdc · 192 | Cursor rules | teststylearchtesting-strategy+1 | 74/100 | 3 days ago | |
| skindhu/AI-TASK-MANAGER.cursor/rules/utilities.mdc · 192 | Cursor rules | securitydocs | 54/100 | 3 days ago | |
| skindhu/AI-TASK-MANAGERassets/.windsurfrules · 192 | Windsurf rules | setup | 40/100 | 3 days ago |
Diff against .cursor/rules/ui.mdc Diff against .cursor/rules/architecture.mdc Diff against .cursor/rules/cursor_rules.mdc Diff against .cursor/rules/dependencies.mdc Diff against .cursor/rules/dev_workflow.mdc Diff against .cursor/rules/new_features.mdc Diff against .cursor/rules/self_improve.mdc Diff against .cursor/rules/tasks.mdc Diff against .cursor/rules/tests.mdc Diff against .cursor/rules/utilities.mdc Diff against assets/.windsurfrules
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
