Skip to content

Commit 7a547b6

Browse files
committed
chore(cli): add help document
1 parent bc102f6 commit 7a547b6

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/index.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,29 @@ import { $, argv, chalk, fs, glob, path } from 'zx'
55
import { select } from '@inquirer/prompts'
66
import { readPackageJSON } from 'pkg-types'
77

8-
if (argv._[0] !== 'sg') {
9-
console.log(chalk.red('Do you want to use `sg` cmd?'))
8+
function printHelp() {
9+
console.log(`
10+
Rewriting at Vue Macros using ast-grep.
11+
12+
${chalk.underline('Usage:')} vue-macros <command> [directory] {(default current directory)}
13+
14+
${chalk.underline('Commands:')}
15+
sg Rewrite code in specified directory
16+
17+
${chalk.underline('Options:')}
18+
-h, --help Print help (see more with '--help')
19+
-V, --version Print version
20+
`)
21+
}
22+
if (argv._[0] !== 'sg' || argv.help || argv.h) {
23+
printHelp()
24+
process.exit()
25+
}
26+
27+
const dirname = path.dirname(fileURLToPath(import.meta.url))
28+
if (argv.v || argv.version) {
29+
const localPackageJson = await readPackageJSON(dirname)
30+
console.log(`${localPackageJson.name} ${localPackageJson.version}`)
1031
process.exit()
1132
}
1233

@@ -50,12 +71,6 @@ if (macro === 'short-v-model') {
5071
})
5172
}
5273

53-
const dirname = path.dirname(fileURLToPath(import.meta.url))
54-
if (argv.v || argv.version) {
55-
const localPackageJson = await readPackageJSON(dirname)
56-
console.log(`${localPackageJson.name} ${localPackageJson.version}`)
57-
}
58-
5974
const target = path.resolve(argv._.at(1) || './src')
6075
async function toSetupSFC() {
6176
const extname = path.extname(target)

0 commit comments

Comments
 (0)