| 1 | import { Command } from "commander"; |
| 2 | import path from "path"; |
| 3 | import pc from "picocolors"; |
| 4 | import { createBoilerplateFolder } from "./create-boilerplate"; |
| 5 | import { createCompletionSpec } from "./create-spec"; |
| 6 | |
| 7 | interface Options { |
| 8 | here?: boolean; |
| 9 | } |
| 10 | |
| 11 | async function runProgram(specName: string, options: Options) { |
| 12 | const { here } = options; |
| 13 | try { |
| 14 | if (!here) { |
| 15 | createBoilerplateFolder(); |
| 16 | console.log("----"); |
| 17 | } |
| 18 | createCompletionSpec( |
| 19 | specName, |
| 20 | here ? process.cwd() : path.resolve(process.cwd(), ".fig", "autocomplete", "src") |
| 21 | ); |
| 22 | } catch (error) { |
| 23 | console.log(pc.red((error as Error).message)); |
| 24 | process.exit(1); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | export const program = new Command("create-completion-spec") |
| 29 | .description("Setup fig folder and create spec with the given name") |
| 30 | .arguments("<name>") |
| 31 | .option("--here", "Set if the spec should be created in the current folder") |
| 32 | .action(runProgram); |