mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
Add hidden property to slash commands (#7797)
This commit is contained in:
@@ -349,4 +349,36 @@ describe('CommandService', () => {
|
||||
expect(deployExtension).toBeDefined();
|
||||
expect(deployExtension?.description).toBe('[gcp] Deploy to Google Cloud');
|
||||
});
|
||||
|
||||
it('should filter out hidden commands', async () => {
|
||||
const visibleCommand = createMockCommand('visible', CommandKind.BUILT_IN);
|
||||
const hiddenCommand = {
|
||||
...createMockCommand('hidden', CommandKind.BUILT_IN),
|
||||
hidden: true,
|
||||
};
|
||||
const initiallyVisibleCommand = createMockCommand(
|
||||
'initially-visible',
|
||||
CommandKind.BUILT_IN,
|
||||
);
|
||||
const hiddenOverrideCommand = {
|
||||
...createMockCommand('initially-visible', CommandKind.FILE),
|
||||
hidden: true,
|
||||
};
|
||||
|
||||
const mockLoader = new MockCommandLoader([
|
||||
visibleCommand,
|
||||
hiddenCommand,
|
||||
initiallyVisibleCommand,
|
||||
hiddenOverrideCommand,
|
||||
]);
|
||||
|
||||
const service = await CommandService.create(
|
||||
[mockLoader],
|
||||
new AbortController().signal,
|
||||
);
|
||||
|
||||
const commands = service.getCommands();
|
||||
expect(commands).toHaveLength(1);
|
||||
expect(commands[0].name).toBe('visible');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -85,7 +85,9 @@ export class CommandService {
|
||||
});
|
||||
}
|
||||
|
||||
const finalCommands = Object.freeze(Array.from(commandMap.values()));
|
||||
const finalCommands = Object.freeze(
|
||||
Array.from(commandMap.values()).filter((cmd) => !cmd.hidden),
|
||||
);
|
||||
return new CommandService(finalCommands);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ export const corgiCommand: SlashCommand = {
|
||||
name: 'corgi',
|
||||
description: 'Toggles corgi mode.',
|
||||
kind: CommandKind.BUILT_IN,
|
||||
hidden: true,
|
||||
action: (context, _args) => {
|
||||
context.ui.toggleCorgiMode();
|
||||
},
|
||||
|
||||
@@ -170,6 +170,7 @@ export interface SlashCommand {
|
||||
name: string;
|
||||
altNames?: string[];
|
||||
description: string;
|
||||
hidden?: boolean;
|
||||
|
||||
kind: CommandKind;
|
||||
|
||||
|
||||
@@ -64,29 +64,27 @@ export const Help: React.FC<Help> = ({ commands }) => (
|
||||
<Text bold color={Colors.Foreground}>
|
||||
Commands:
|
||||
</Text>
|
||||
{commands
|
||||
.filter((command) => command.description)
|
||||
.map((command: SlashCommand) => (
|
||||
<Box key={command.name} flexDirection="column">
|
||||
<Text color={Colors.Foreground}>
|
||||
<Text bold color={Colors.AccentPurple}>
|
||||
{' '}
|
||||
/{command.name}
|
||||
</Text>
|
||||
{command.description && ' - ' + command.description}
|
||||
{commands.map((command: SlashCommand) => (
|
||||
<Box key={command.name} flexDirection="column">
|
||||
<Text color={Colors.Foreground}>
|
||||
<Text bold color={Colors.AccentPurple}>
|
||||
{' '}
|
||||
/{command.name}
|
||||
</Text>
|
||||
{command.subCommands &&
|
||||
command.subCommands.map((subCommand) => (
|
||||
<Text key={subCommand.name} color={Colors.Foreground}>
|
||||
<Text bold color={Colors.AccentPurple}>
|
||||
{' '}
|
||||
{subCommand.name}
|
||||
</Text>
|
||||
{subCommand.description && ' - ' + subCommand.description}
|
||||
{command.description && ' - ' + command.description}
|
||||
</Text>
|
||||
{command.subCommands &&
|
||||
command.subCommands.map((subCommand) => (
|
||||
<Text key={subCommand.name} color={Colors.Foreground}>
|
||||
<Text bold color={Colors.AccentPurple}>
|
||||
{' '}
|
||||
{subCommand.name}
|
||||
</Text>
|
||||
))}
|
||||
</Box>
|
||||
))}
|
||||
{subCommand.description && ' - ' + subCommand.description}
|
||||
</Text>
|
||||
))}
|
||||
</Box>
|
||||
))}
|
||||
<Text color={Colors.Foreground}>
|
||||
<Text bold color={Colors.AccentPurple}>
|
||||
{' '}
|
||||
|
||||
@@ -220,6 +220,18 @@ describe('useSlashCommandProcessor', () => {
|
||||
expect(fileAction).toHaveBeenCalledTimes(1);
|
||||
expect(builtinAction).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not include hidden commands in the command list', async () => {
|
||||
const visibleCommand = createTestCommand({ name: 'visible' });
|
||||
const hiddenCommand = createTestCommand({ name: 'hidden', hidden: true });
|
||||
const result = setupProcessorHook([visibleCommand, hiddenCommand]);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.slashCommands).toHaveLength(1);
|
||||
});
|
||||
|
||||
expect(result.current.slashCommands[0].name).toBe('visible');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Command Execution Logic', () => {
|
||||
|
||||
@@ -443,6 +443,7 @@ export function useSlashCompletion(props: UseSlashCompletionProps): {
|
||||
commands.filter(
|
||||
(cmd) =>
|
||||
cmd.description &&
|
||||
!cmd.hidden &&
|
||||
(cmd.name.toLowerCase().startsWith(partial.toLowerCase()) ||
|
||||
cmd.altNames?.some((alt) =>
|
||||
alt.toLowerCase().startsWith(partial.toLowerCase()),
|
||||
|
||||
@@ -158,6 +158,7 @@ describe('createContentGeneratorConfig', () => {
|
||||
});
|
||||
|
||||
it('should configure for Vertex AI using GCP project and location when set', async () => {
|
||||
vi.stubEnv('GOOGLE_API_KEY', undefined);
|
||||
vi.stubEnv('GOOGLE_CLOUD_PROJECT', 'env-gcp-project');
|
||||
vi.stubEnv('GOOGLE_CLOUD_LOCATION', 'env-gcp-location');
|
||||
const config = await createContentGeneratorConfig(
|
||||
|
||||
Reference in New Issue
Block a user