Files
aicommits/src/cli.ts
2023-03-09 21:50:52 +09:00

52 lines
1.0 KiB
TypeScript

import { cli } from 'cleye';
import { description, version } from '../package.json';
import aicommits from './commands/aicommits.js';
import prepareCommitMessageHook from './commands/prepare-commit-msg-hook.js';
import configCommand from './commands/config.js';
import hookCommand, { isCalledFromGitHook } from './commands/hook.js';
const rawArgv = process.argv.slice(2);
cli(
{
name: 'aicommits',
version,
/**
* Since this is a wrapper around `git commit`,
* flags should not overlap with it
* https://git-scm.com/docs/git-commit
*/
flags: {
generate: {
type: Number,
description: 'Number of messages to generate. (Warning: generating multiple costs more) (default: 1)',
alias: 'g',
},
},
commands: [
configCommand,
hookCommand,
],
help: {
description,
},
ignoreArgv: type => type === 'unknown-flag' || type === 'argument',
},
(argv) => {
if (isCalledFromGitHook) {
prepareCommitMessageHook();
} else {
aicommits(
argv.flags.generate,
rawArgv,
);
}
},
rawArgv,
);