fix: dont log unknown config property

This commit is contained in:
Hiroki Osame
2023-03-10 15:39:13 +09:00
parent d6a6a5b025
commit 09c2c98e05
3 changed files with 17 additions and 3 deletions

View File

@@ -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,8 +14,10 @@ export default command({
if (mode === 'get') {
const config = await getConfig();
for (const key of keyValues) {
if (hasOwn(config, key)) {
console.log(`${key}=${config[key as keyof typeof config]}`);
}
}
return;
}

View File

@@ -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,

View File

@@ -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();
});
});