Learn how to use the cloving generate code
command to generate and manage code snippets.
cloving generate code [options]
There is also shortcut to save you a few chars:
cloving g code [options]
And if you really hate typing:
cloving g c [options]
The cloving generate code
command helps you generate code snippets based on a prompt and context files. It uses the AI APIs configured with cloving config
as well as the cloving.json file created by cloving init
to analyze the prompt and generate relevant code, which can then be reviewed, revised, or saved.
This command accepts the following options:
The cloving generate code
command uses the following interactive prompts if you don't set them up in the CLI options:
Here is an example of what a code generation session might look like:
$ cloving generate code --prompt "Create a function to calculate the factorial of a number"
Generated code:
1. **src/factorial.ts**:
```typescript
function factorial(n: number): number {
if (n <0) return -1
else if (n === 0) return 1
else return n * factorial(n - 1)
}
```
What would you like to do?
1. Revise
2. Explain
3. Save a Source Code File
4. Save All Source Code Files
5. Copy Source Code to Clipboard
6. Copy Entire Response to Clipboard
7. Done
If you choose to save the code, the process continues as follows:
$ cloving generate code --prompt "Create a function to calculate the factorial of a number" --save
Generated code:
1. **src/factorial.ts**:
```typescript
function factorial(n: number): number {
if (n < 0) return -1
else if (n === 0) return 1
else return n * factorial(n - 1)
}
```
Saving generated files...
src/factorial.ts has been saved.