diff options
| author | Marat Boshernitsan <[email protected]> | 2025-06-12 17:17:29 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-12 17:17:29 -0700 |
| commit | 181abde2ffa8f1f68b6c540a5600346116cb5145 (patch) | |
| tree | 0081aeb6e48116865ed7d081024fc789dfae8c80 /packages/cli/src/config/config.ts | |
| parent | 3c3da655b0fd4dafce7a642c4112e2375e3fa02f (diff) | |
Reduce coupling between core and cli packages (#961)
Co-authored-by: Marat Boshernitsan <[email protected]>
Diffstat (limited to 'packages/cli/src/config/config.ts')
| -rw-r--r-- | packages/cli/src/config/config.ts | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 2f989883..3ee03c82 100644 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -9,16 +9,20 @@ import { hideBin } from 'yargs/helpers'; import process from 'node:process'; import { Config, - loadEnvironment, loadServerHierarchicalMemory, setGeminiMdFilename as setServerGeminiMdFilename, getCurrentGeminiMdFilename, ApprovalMode, ContentGeneratorConfig, + GEMINI_CONFIG_DIR as GEMINI_DIR, } from '@gemini-cli/core'; import { Settings } from './settings.js'; import { getEffectiveModel } from '../utils/modelCheck.js'; import { ExtensionConfig } from './extension.js'; +import * as dotenv from 'dotenv'; +import * as fs from 'node:fs'; +import * as path from 'node:path'; +import * as os from 'node:os'; // Simple console logger for now - replace with actual logger if available const logger = { @@ -196,6 +200,13 @@ export async function loadCliConfig( fileFilteringAllowBuildArtifacts: settings.fileFiltering?.allowBuildArtifacts, checkpoint: argv.checkpoint, + proxy: + process.env.HTTPS_PROXY || + process.env.https_proxy || + process.env.HTTP_PROXY || + process.env.http_proxy, + cwd: process.cwd(), + telemetryOtlpEndpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT, }); } @@ -259,3 +270,39 @@ async function createContentGeneratorConfig( return config; } + +function findEnvFile(startDir: string): string | null { + let currentDir = path.resolve(startDir); + while (true) { + // prefer gemini-specific .env under GEMINI_DIR + const geminiEnvPath = path.join(currentDir, GEMINI_DIR, '.env'); + if (fs.existsSync(geminiEnvPath)) { + return geminiEnvPath; + } + const envPath = path.join(currentDir, '.env'); + if (fs.existsSync(envPath)) { + return envPath; + } + const parentDir = path.dirname(currentDir); + if (parentDir === currentDir || !parentDir) { + // check .env under home as fallback, again preferring gemini-specific .env + const homeGeminiEnvPath = path.join(os.homedir(), GEMINI_DIR, '.env'); + if (fs.existsSync(homeGeminiEnvPath)) { + return homeGeminiEnvPath; + } + const homeEnvPath = path.join(os.homedir(), '.env'); + if (fs.existsSync(homeEnvPath)) { + return homeEnvPath; + } + return null; + } + currentDir = parentDir; + } +} + +export function loadEnvironment(): void { + const envFilePath = findEnvFile(process.cwd()); + if (envFilePath) { + dotenv.config({ path: envFilePath }); + } +} |
