|
| 1 | +# Custom CLI Commands |
| 2 | + |
| 3 | +MyCoder allows you to define custom CLI commands in your `mycoder.config.js` file. These commands can have arguments and will execute predefined prompts using JavaScript functions. |
| 4 | + |
| 5 | +## Configuration |
| 6 | + |
| 7 | +To add custom commands, add a `commands` section to your `mycoder.config.js` file: |
| 8 | + |
| 9 | +```js |
| 10 | +// mycoder.config.js |
| 11 | +export default { |
| 12 | + // ... other config options |
| 13 | + |
| 14 | + // Custom commands |
| 15 | + commands: { |
| 16 | + search: { |
| 17 | + description: 'Search for a term in the codebase', |
| 18 | + args: [{ name: 'term', description: 'Search term', required: true }], |
| 19 | + execute: (args) => { |
| 20 | + return `Find all instances of ${args.term} in the codebase and suggest improvements`; |
| 21 | + }, |
| 22 | + }, |
| 23 | + |
| 24 | + 'fix-issue': { |
| 25 | + description: 'Fix a GitHub issue', |
| 26 | + args: [ |
| 27 | + { name: 'issue', description: 'Issue number', required: true }, |
| 28 | + { name: 'scope', description: 'Scope of the fix', default: 'full' }, |
| 29 | + ], |
| 30 | + execute: (args) => { |
| 31 | + return `Analyze GitHub issue #${args.issue} and implement a ${args.scope} fix`; |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | +}; |
| 36 | +``` |
| 37 | + |
| 38 | +## Command Structure |
| 39 | + |
| 40 | +Each command in the `commands` object has the following properties: |
| 41 | + |
| 42 | +- `description` (optional): A description of what the command does |
| 43 | +- `args` (optional): An array of argument definitions |
| 44 | + - `name`: The name of the argument |
| 45 | + - `description` (optional): A description of the argument |
| 46 | + - `required` (optional): Whether the argument is required (default: false) |
| 47 | + - `default` (optional): Default value for the argument if not provided |
| 48 | +- `execute` (required): A function that takes the arguments and returns a prompt string |
| 49 | + |
| 50 | +## Using Commands |
| 51 | + |
| 52 | +Once defined in your config file, you can use your custom commands like any other MyCoder command: |
| 53 | + |
| 54 | +```bash |
| 55 | +# Using the search command |
| 56 | +mycoder search "deprecated API" |
| 57 | + |
| 58 | +# Using the fix-issue command with all arguments |
| 59 | +mycoder fix-issue 123 --scope partial |
| 60 | + |
| 61 | +# Using the fix-issue command with default scope |
| 62 | +mycoder fix-issue 123 |
| 63 | +``` |
| 64 | + |
| 65 | +## Advanced Usage |
| 66 | + |
| 67 | +The `execute` function can also be asynchronous, allowing you to fetch data or perform other async operations before generating the prompt: |
| 68 | + |
| 69 | +```js |
| 70 | +"github-pr": { |
| 71 | + description: "Review a GitHub PR", |
| 72 | + args: [ |
| 73 | + { name: "repo", description: "Repository name", required: true }, |
| 74 | + { name: "pr", description: "PR number", required: true } |
| 75 | + ], |
| 76 | + execute: async (args) => { |
| 77 | + // You could fetch PR details here if needed |
| 78 | + return `Review GitHub PR #${args.pr} in repository ${args.repo} and provide feedback`; |
| 79 | + } |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +## Command Naming |
| 84 | + |
| 85 | +Command names must: |
| 86 | + |
| 87 | +- Start with a letter |
| 88 | +- Contain only letters, numbers, hyphens, and underscores |
| 89 | + |
| 90 | +## Limitations |
| 91 | + |
| 92 | +- Custom commands cannot override built-in commands |
| 93 | +- The `execute` function must return a string (the prompt to execute) |
0 commit comments