Question flag (#125)

This commit is contained in:
Allen Hutchison 2025-04-22 18:32:03 -07:00 committed by GitHub
parent ef7dcdb49e
commit 9bc9c6e6c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 4 deletions

View File

@ -20,6 +20,7 @@ interface CliArgs {
target_dir: string | undefined; target_dir: string | undefined;
model: string | undefined; model: string | undefined;
debug_mode: boolean | undefined; debug_mode: boolean | undefined;
question: string | undefined;
} }
function parseArguments(): CliArgs { function parseArguments(): CliArgs {
@ -42,6 +43,12 @@ function parseArguments(): CliArgs {
description: 'Whether to run in debug mode. Defaults to false.', description: 'Whether to run in debug mode. Defaults to false.',
default: false, default: false,
}) })
.option('question', {
alias: 'q',
type: 'string',
description:
'The question to pass to the command when using piped input.',
})
.help() .help()
.alias('h', 'help') .alias('h', 'help')
.strict().argv; .strict().argv;
@ -71,6 +78,7 @@ export function loadCliConfig(): Config {
argv.model || DEFAULT_GEMINI_MODEL, argv.model || DEFAULT_GEMINI_MODEL,
argv.target_dir || process.cwd(), argv.target_dir || process.cwd(),
argv.debug_mode || false, argv.debug_mode || false,
argv.question || '',
// TODO: load passthroughCommands from .env file // TODO: load passthroughCommands from .env file
); );
} }

View File

@ -13,9 +13,10 @@ import { GeminiClient } from '@gemini-code/server';
async function main() { async function main() {
const config = loadCliConfig(); const config = loadCliConfig();
let input = config.getQuestion();
// Render UI, passing necessary config values and initial input // Render UI, passing necessary config values. Check that there is no command line question.
if (process.stdin.isTTY) { if (process.stdin.isTTY && input?.length === 0) {
render( render(
React.createElement(App, { React.createElement(App, {
config, config,
@ -24,7 +25,11 @@ async function main() {
return; return;
} }
const input = await readStdin(); // If not a TTY, read from stdin
// This is for cases where the user pipes input directly into the command
if (!process.stdin.isTTY) {
input += await readStdin();
}
if (!input) { if (!input) {
console.error('No input provided via stdin.'); console.error('No input provided via stdin.');
process.exit(1); process.exit(1);

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import { exec as _exec, exec } from 'child_process'; import { exec as _exec } from 'child_process';
import { useState, useRef, useCallback, useEffect } from 'react'; import { useState, useRef, useCallback, useEffect } from 'react';
import { useInput } from 'ink'; import { useInput } from 'ink';
import { import {

View File

@ -26,6 +26,7 @@ export class Config {
private targetDir: string; private targetDir: string;
private toolRegistry: ToolRegistry; private toolRegistry: ToolRegistry;
private debugMode: boolean; private debugMode: boolean;
private question: string | undefined;
private passthroughCommands: string[]; private passthroughCommands: string[];
constructor( constructor(
@ -33,12 +34,14 @@ export class Config {
model: string, model: string,
targetDir: string, targetDir: string,
debugMode: boolean, debugMode: boolean,
question: string,
passthroughCommands?: string[], passthroughCommands?: string[],
) { ) {
this.apiKey = apiKey; this.apiKey = apiKey;
this.model = model; this.model = model;
this.targetDir = targetDir; this.targetDir = targetDir;
this.debugMode = debugMode; this.debugMode = debugMode;
this.question = question;
this.passthroughCommands = this.passthroughCommands =
passthroughCommands || DEFAULT_PASSTHROUGH_COMMANDS; passthroughCommands || DEFAULT_PASSTHROUGH_COMMANDS;
@ -64,6 +67,9 @@ export class Config {
getDebugMode(): boolean { getDebugMode(): boolean {
return this.debugMode; return this.debugMode;
} }
getQuestion(): string | undefined {
return this.question;
}
getPassthroughCommands(): string[] { getPassthroughCommands(): string[] {
return this.passthroughCommands; return this.passthroughCommands;
@ -98,6 +104,7 @@ export function createServerConfig(
model: string, model: string,
targetDir: string, targetDir: string,
debugMode: boolean, debugMode: boolean,
question: string,
passthroughCommands?: string[], passthroughCommands?: string[],
): Config { ): Config {
return new Config( return new Config(
@ -105,6 +112,7 @@ export function createServerConfig(
model, model,
path.resolve(targetDir), path.resolve(targetDir),
debugMode, debugMode,
question,
passthroughCommands, passthroughCommands,
); );
} }