Skip to content

Commit 2c5d4d5

Browse files
committed
✨ Feat: add -v and -h flags
1 parent a7ae4df commit 2c5d4d5

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

lib/cli.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22
import chalk from 'chalk';
33
import execa from 'execa';
4+
import yargs from 'yargs';
45
import inquirer from 'inquirer';
56
import updateNotifier from 'update-notifier';
67

@@ -11,17 +12,28 @@ import { choices, questions } from './promptConfig';
1112
const configuration = getConfig();
1213
const choicesList = choices(configuration);
1314
const questionsList = questions(choicesList);
15+
const argv = yargs
16+
.usage('Usage: $0')
17+
.alias('v', 'version')
18+
.describe('v', 'Version number')
19+
.help('h')
20+
.alias('h', 'help')
21+
.argv;
1422

1523
updateNotifier({ pkg }).notify();
1624

17-
inquirer.prompt(questionsList).then((answers) => {
18-
const message = answers.moreInfo ? `${answers.editor}` : `${answers.type} ${answers.description}`;
25+
if (argv.v) {
26+
console.log(`v${pkg.version}`);
27+
} else {
28+
inquirer.prompt(questionsList).then((answers) => {
29+
const message = answers.moreInfo ? `${answers.editor}` : `${answers.type} ${answers.description}`;
30+
31+
return execa('git', ['commit', '-m', message])
32+
.then(result => console.log(result.stdout))
33+
.catch(() => {
34+
console.error(chalk.red("Have you thought about 'git add' some files? Add files and try run following again:\n"));
35+
console.error(chalk.green(`git commit -m "${message}"`));
36+
});
37+
});
38+
}
1939

20-
return execa('git', ['commit', '-m', message])
21-
.then(result => console.log(result.stdout))
22-
.catch(() => {
23-
console.log();
24-
console.error(chalk.red("Have you thought about 'git add' some files? Add files and try run following again:\n"));
25-
console.error(chalk.green(`git commit -m "${message}"`));
26-
});
27-
});

0 commit comments

Comments
 (0)