Files
qwen-code/packages/cli/src/config/config.ts
Evan Senter 3fce6cea27 Starting to modularize into separate cli / server packages. (#55)
* Starting to move a lot of code into packages/server

* More of the massive refactor, builds and runs, some issues though.

* Fixing outstanding issue with double messages.

* Fixing a minor UI issue.

* Fixing the build post-merge.

* Running formatting.

* Addressing comments.
2025-04-19 19:45:42 +01:00

72 lines
1.9 KiB
TypeScript

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
import process from 'node:process';
// Import server config logic
import {
Config,
loadEnvironment,
createServerConfig,
} from '@gemini-code/server';
const DEFAULT_GEMINI_MODEL = 'gemini-2.5-flash-preview-04-17';
// Keep CLI-specific argument parsing
interface CliArgs {
target_dir: string | undefined;
model: string | undefined;
}
function parseArguments(): CliArgs {
const argv = yargs(hideBin(process.argv))
.option('target_dir', {
alias: 'd',
type: 'string',
description:
'The target directory for Gemini operations. Defaults to the current working directory.',
})
.option('model', {
alias: 'm',
type: 'string',
description: `The Gemini model to use. Defaults to ${DEFAULT_GEMINI_MODEL}.`,
default: DEFAULT_GEMINI_MODEL,
})
.help()
.alias('h', 'help')
.strict().argv;
return argv as unknown as CliArgs;
}
// Renamed function for clarity
export function loadCliConfig(): Config {
// Load .env file using logic from server package
loadEnvironment();
// Check API key (CLI responsibility)
if (!process.env.GEMINI_API_KEY) {
console.log(
'GEMINI_API_KEY is not set. See https://ai.google.dev/gemini-api/docs/api-key to obtain one. ' +
'Please set it in your .env file or as an environment variable.',
);
process.exit(1);
}
// Parse CLI arguments
const argv = parseArguments();
// Create config using factory from server package
return createServerConfig(
process.env.GEMINI_API_KEY,
argv.model || DEFAULT_GEMINI_MODEL,
argv.target_dir || process.cwd(),
);
}
// The globalConfig export is problematic, CLI entry point (gemini.ts) should call loadCliConfig
// export const globalConfig = loadCliConfig(); // Remove or replace global export