| 1 | import { createCompletionSpec } from "create-completion-spec"; |
| 2 | import { Command } from "commander"; |
| 3 | import readline from "readline"; |
| 4 | import path from "path"; |
| 5 | import chalk from "chalk"; |
| 6 | |
| 7 | const program = new Command("create-spec") |
| 8 | .description("create spec with given name") |
| 9 | .arguments("[name]") |
| 10 | .action((specName) => { |
| 11 | const autocompleteFolder = path.resolve(process.cwd(), "src"); |
| 12 | if (!specName) { |
| 13 | const rInterface = readline.createInterface({ |
| 14 | input: process.stdin, |
| 15 | output: process.stdout, |
| 16 | }); |
| 17 | rInterface.question( |
| 18 | "What's the name of the CLI tool you want to create an autocomplete spec for: ", |
| 19 | async (answer) => { |
| 20 | try { |
| 21 | createCompletionSpec(answer, autocompleteFolder); |
| 22 | } catch (error) { |
| 23 | console.log(chalk.red((error as Error).message)); |
| 24 | process.exit(1); |
| 25 | } finally { |
| 26 | rInterface.close(); |
| 27 | } |
| 28 | } |
| 29 | ); |
| 30 | } else { |
| 31 | createCompletionSpec(specName, autocompleteFolder); |
| 32 | } |
| 33 | }); |
| 34 | |
| 35 | export default program; |