diff --git a/src/ai.ts b/src/ai.ts index 0408035..ec927b7 100644 --- a/src/ai.ts +++ b/src/ai.ts @@ -28,7 +28,7 @@ export interface CommitMessageData { message: string } -export async function generateByAI(config: Config, type: string, scope: string, message: string) { +export async function generateByAI(config: Config, type: string, scope: string) { const typeList = Object.keys(config.data) const verbose = config.verbose const s = spinner() @@ -96,7 +96,7 @@ Based on the information above, type, scope and message respectively: scope = data.scope.toLowerCase() if (type === '') type = data.type.toLowerCase() - message = data.message + let message = data.message message = message[0].toLowerCase() + message.slice(1) const cmd = getCMD({ type, scope, body: message, icon: config.showIcon ? config.data[type].emoji : '' }) s.stop('Generated') @@ -108,6 +108,7 @@ Based on the information above, type, scope and message respectively: } if (config.dryRun) { log.info(`Dry run: ${cmd}`) + process.exit(0) } else { await new Promise((resolve, reject) => { @@ -121,6 +122,7 @@ Based on the information above, type, scope and message respectively: resolve() }) }) + process.exit(0) } } catch (e) { diff --git a/src/index.ts b/src/index.ts index 9d1d26f..9a6df7a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,14 +41,8 @@ program .option('-no-i, --no-icon', 'Do not show icon') .option('-v, --verbose', 'Verbose mode') .version(`v${version}`, '-V, --version', 'Output the current version') - .arguments('[type] [body|scope] [body]').action(async (type, scope = '', body = '') => { + .arguments('[type] [body|scope] [body]').action(async (type = '', scope = '', body = '') => { const options = program.opts() - if (body === '') { - body = scope - scope = '' - } - if (!type) - type = '' config.showIcon = !options.noIcon config.verbose = options.verbose config.ai.enabled = options.ai @@ -57,9 +51,13 @@ program intro(`@gitcm/cli - v${version}`) if (config.ai.enabled) { checkAI() - await generateByAI(config, type, scope, body) + await generateByAI(config, type, scope) } else { + if (body === '') { + body = scope + scope = '' + } await waitPrompt(config, type, scope, body) } }) @@ -147,8 +145,6 @@ function isType(key: string) { } async function waitPrompt(config: Config, type: string, scope: string, body: string) { - intro(`@gitcm/cli - v${version}`) - if (type !== '' && !isType(type)) { log.error(`Invalid commit type: ${type}. ` + `Commit type must be one of ${typeList.join(', ')}`) process.exit(1)