-
-
Notifications
You must be signed in to change notification settings - Fork 792
/
Copy pathcli.ts
executable file
·39 lines (32 loc) · 1.22 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env node
import cac from 'cac'
import main, { list } from '.'
import { name, version } from '../package.json'
const cli = cac(name)
cli
.command('<template> [project]', 'Create new project from a template')
.option('-f, --force', 'Overwrite if the target exists')
.option('-o, --offline', 'Try to use an offline template')
// .option('-d, --debug', 'Output detailed exception when exception occurs')
.allowUnknownOptions() // for prompts override.
.example(' # with an official template')
.example(` $ ${name} <template> [project]`)
.example(' # with a custom github repo')
.example(` $ ${name} <owner>/<repo> [project]`)
.action(main)
cli
.command('list [owner]', 'Show all available templates')
.alias('ls')
.option('-j, --json', 'Output with json format')
.option('-s, --short', 'Output with short format')
.action(list)
cli.help().version(version).parse()
// https://github.com/cacjs/cac#error-handling
const onError = (err: Error): void => {
// output details when exception occurs
cli.options.debug as boolean && console.error(err)
console.error('Exception occurred: ' + err.message)
process.exit(1)
}
process.on('uncaughtException', onError)
process.on('unhandledRejection', onError)