From 09c2c98e056726cbd7323f5058a5ab07bcec0863 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Fri, 10 Mar 2023 15:39:13 +0900 Subject: [PATCH] fix: dont log unknown config property --- src/commands/config.ts | 6 ++++-- src/utils/config.ts | 2 +- tests/specs/config.ts | 12 ++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/commands/config.ts b/src/commands/config.ts index 5ca74d4..3aeb0b4 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -1,6 +1,6 @@ import { command } from 'cleye'; import { red } from 'kolorist'; -import { getConfig, setConfigs } from '../utils/config.js'; +import { hasOwn, getConfig, setConfigs } from '../utils/config.js'; import { KnownError, handleCliError } from '../utils/error.js'; export default command({ @@ -14,7 +14,9 @@ export default command({ if (mode === 'get') { const config = await getConfig(); for (const key of keyValues) { - console.log(`${key}=${config[key as keyof typeof config]}`); + if (hasOwn(config, key)) { + console.log(`${key}=${config[key as keyof typeof config]}`); + } } return; } diff --git a/src/utils/config.ts b/src/utils/config.ts index 644612a..d029e9a 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -6,7 +6,7 @@ import { fileExists } from './fs.js'; import { KnownError } from './error.js'; const { hasOwnProperty } = Object.prototype; -const hasOwn = (object: unknown, key: PropertyKey) => hasOwnProperty.call(object, key); +export const hasOwn = (object: unknown, key: PropertyKey) => hasOwnProperty.call(object, key); const parseAssert = ( name: string, diff --git a/tests/specs/config.ts b/tests/specs/config.ts index 58442af..a571ef1 100644 --- a/tests/specs/config.ts +++ b/tests/specs/config.ts @@ -50,6 +50,18 @@ export default testSuite(({ describe }) => { expect(stdout).toBe(openAiToken); }); + await test('reading unknown config', async () => { + await fs.appendFile(configPath, 'UNKNOWN=1'); + + const { stdout, stderr } = await execaNode(aicommitsPath, ['config', 'get', 'UNKNOWN'], { + env, + reject: false, + }); + + expect(stdout).toBe(''); + expect(stderr).toBe(''); + }); + await fixture.rm(); }); });