diff --git a/changelog.md b/changelog.md index e6c986b..f6cc4d5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## [0.4.0] - 04/04/2026 +- Set api key + ## [0.3.9] - 04/04/2026 - Secrets bypass diff --git a/package.json b/package.json index 9e80931..0d8d109 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codeant-cli", - "version": "0.3.9", + "version": "0.4.0", "description": "Code review CLI tool", "type": "module", "bin": { diff --git a/src/commands/getApiKey.js b/src/commands/getApiKey.js new file mode 100644 index 0000000..9afa0e8 --- /dev/null +++ b/src/commands/getApiKey.js @@ -0,0 +1,30 @@ +import React, { useEffect } from 'react'; +import { Text, Box, useApp } from 'ink'; +import { getConfigValue } from '../utils/config.js'; + +export default function GetApiKey() { + const { exit } = useApp(); + + const apiKey = getConfigValue('apiKeyV2'); + + useEffect(() => { + exit(); + }, []); + + if (!apiKey) { + return React.createElement( + Box, + { flexDirection: 'column', padding: 1 }, + React.createElement(Text, { color: 'yellow' }, 'No CodeAnt API key configured.'), + React.createElement(Text, { color: 'gray' }, 'Set one with: codeant set-codeant-api-key ') + ); + } + + const masked = apiKey.slice(0, 4) + '…' + apiKey.slice(-4); + + return React.createElement( + Box, + { flexDirection: 'column', padding: 1 }, + React.createElement(Text, { bold: true }, 'CodeAnt API Key: ', masked) + ); +} diff --git a/src/commands/setApiKey.js b/src/commands/setApiKey.js new file mode 100644 index 0000000..1d38978 --- /dev/null +++ b/src/commands/setApiKey.js @@ -0,0 +1,37 @@ +import React, { useEffect } from 'react'; +import { Text, Box, useApp } from 'ink'; +import { setConfigValue, CONFIG_FILE } from '../utils/config.js'; + +export default function SetApiKey({ apiKey }) { + const { exit } = useApp(); + + useEffect(() => { + if (!apiKey) { + exit(new Error('API key is required')); + return; + } + + try { + setConfigValue('apiKeyV2', apiKey); + exit(); + } catch (err) { + exit(err); + } + }, []); + + if (!apiKey) { + return React.createElement( + Box, + { flexDirection: 'column', padding: 1 }, + React.createElement(Text, { color: 'red' }, '✗ Error: API key is required'), + React.createElement(Text, { color: 'gray' }, 'Usage: codeant set-codeant-api-key ') + ); + } + + return React.createElement( + Box, + { flexDirection: 'column', padding: 1 }, + React.createElement(Text, { color: 'green' }, '✓ CodeAnt API key saved.'), + React.createElement(Text, { color: 'gray' }, 'Saved to: ', CONFIG_FILE) + ); +} diff --git a/src/index.js b/src/index.js index 98cc5cd..b6c8dbf 100755 --- a/src/index.js +++ b/src/index.js @@ -7,6 +7,8 @@ import { createRequire } from 'module'; import Secrets from './commands/secrets.js'; import SetBaseUrl from './commands/setBaseUrl.js'; import GetBaseUrl from './commands/getBaseUrl.js'; +import SetApiKey from './commands/setApiKey.js'; +import GetApiKey from './commands/getApiKey.js'; import Login from './commands/login.js'; import Logout from './commands/logout.js'; import Review from './commands/review.js'; @@ -183,6 +185,20 @@ program render(React.createElement(GetBaseUrl)); }); + program + .command('set-codeant-api-key ') + .description('Set the CodeAnt API key') + .action((key) => { + render(React.createElement(SetApiKey, { apiKey: key })); + }); + + program + .command('get-codeant-api-key') + .description('Show the current CodeAnt API key') + .action(() => { + render(React.createElement(GetApiKey)); + }); + program .command('login') .description('Login to CodeAnt')