* feat(CommandsEnum.ts): add COMMANDS enum
* refactor(api.ts): use CONFIG_MODES enum from config.ts * refactor(config.ts): use COMMANDS and CONFIG_MODES enums, extract validateConfig function * feat(config.ts): add CONFIG_MODES enum and refactor configCommand function to use it * refactor(githook.ts): import COMMANDS enum from CommandsEnum.js file
This commit is contained in:
@@ -5,6 +5,7 @@ import { existsSync, writeFileSync, readFileSync } from 'fs';
|
||||
import { homedir } from 'os';
|
||||
import { intro, outro } from '@clack/prompts';
|
||||
import chalk from 'chalk';
|
||||
import { COMMANDS } from '../CommandsEnum';
|
||||
|
||||
export enum CONFIG_KEYS {
|
||||
OPENAI_API_KEY = 'OPENAI_API_KEY',
|
||||
@@ -12,6 +13,11 @@ export enum CONFIG_KEYS {
|
||||
emoji = 'emoji'
|
||||
}
|
||||
|
||||
export enum CONFIG_MODES {
|
||||
get = 'get',
|
||||
set = 'set'
|
||||
}
|
||||
|
||||
const validateConfig = (
|
||||
key: string,
|
||||
condition: any,
|
||||
@@ -110,7 +116,7 @@ export const setConfig = (keyValues: [key: string, value: string][]) => {
|
||||
|
||||
export const configCommand = command(
|
||||
{
|
||||
name: 'config',
|
||||
name: COMMANDS.config,
|
||||
parameters: ['<mode>', '<key=values...>']
|
||||
},
|
||||
async (argv) => {
|
||||
@@ -118,12 +124,12 @@ export const configCommand = command(
|
||||
try {
|
||||
const { mode, keyValues } = argv._;
|
||||
|
||||
if (mode === 'get') {
|
||||
if (mode === CONFIG_MODES.get) {
|
||||
const config = getConfig() || {};
|
||||
for (const key of keyValues) {
|
||||
outro(`${key}=${config[key as keyof typeof config]}`);
|
||||
}
|
||||
} else if (mode === 'set') {
|
||||
} else if (mode === CONFIG_MODES.set) {
|
||||
await setConfig(
|
||||
keyValues.map((keyValue) => keyValue.split('=') as [string, string])
|
||||
);
|
||||
|
||||
@@ -5,6 +5,7 @@ import { assertGitRepo } from '../utils/git.js';
|
||||
import { existsSync } from 'fs';
|
||||
import chalk from 'chalk';
|
||||
import { intro, outro } from '@clack/prompts';
|
||||
import { COMMANDS } from '../CommandsEnum.js';
|
||||
|
||||
const HOOK_NAME = 'prepare-commit-msg';
|
||||
const SYMLINK_URL = `.git/hooks/${HOOK_NAME}`;
|
||||
@@ -15,7 +16,7 @@ const isHookExists = existsSync(SYMLINK_URL);
|
||||
|
||||
export const hookCommand = command(
|
||||
{
|
||||
name: 'hook',
|
||||
name: COMMANDS.hook,
|
||||
parameters: ['<set/unset>']
|
||||
},
|
||||
async (argv) => {
|
||||
|
||||
Reference in New Issue
Block a user