UNPKG

gitmoji-cli

Version:

A gitmoji client for using emojis on commit messages.

44 lines 1.34 kB
import COMMIT_MODES from "../constants/commit.js"; import FLAGS from "../constants/flags.js"; const isSupportedCommand = (command, options) => { return Object.keys(options).includes(command); }; const determineCommand = (flags, input, options) => { const command = Object.keys(flags).map(flag => flags[flag] && flag).find(flag => options[flag]); return command ? { type: 'flag', command } : { type: 'command', command: input[0] }; }; const getOptionsForCommand = (command, flags, input, type) => { switch (command) { case FLAGS.COMMIT: case FLAGS.HOOK: return { message: flags['message'], mode: command === FLAGS.HOOK ? COMMIT_MODES.HOOK : COMMIT_MODES.CLIENT, scope: flags['scope'], title: flags['title'] }; case FLAGS.SEARCH: return { query: type === 'command' ? input.slice(1) : input }; } return null; }; const findGitmojiCommand = (cli, options) => { const { command, type } = determineCommand(cli.flags, cli.input, options); if (!command || !isSupportedCommand(command, options)) { return cli.showHelp(); } const commandOptions = getOptionsForCommand(command, cli.flags, cli.input, type); return options[command] ? options[command](commandOptions) : cli.showHelp(); }; export default findGitmojiCommand;