Skip to content

Commit 0c0535c

Browse files
authored
Minor cli cleanup: show help when no command provided, hide login/deploy unless plugins installed (#105)
1 parent 0b527f6 commit 0c0535c

File tree

11 files changed

+28
-14
lines changed

11 files changed

+28
-14
lines changed

genkit-tools/cli/src/cli.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
notifyAnalyticsIfFirstRun,
2222
record,
2323
} from '@genkit-ai/tools-common/utils';
24-
import * as clc from 'colorette';
2524
import { Command, program } from 'commander';
2625
import { config } from './commands/config';
2726
import { evalExtractData } from './commands/eval-extract-data';
@@ -57,7 +56,7 @@ const commands: Command[] = [
5756
export async function startCLI(): Promise<void> {
5857
program
5958
.name('genkit')
60-
.description('Google Genkit CLI')
59+
.description('Firebase Genkit CLI')
6160
.version(version)
6261
.hook('preAction', async (_, actionCommand) => {
6362
await notifyAnalyticsIfFirstRun();
@@ -84,12 +83,20 @@ export async function startCLI(): Promise<void> {
8483
for (const command of await getPluginCommands()) program.addCommand(command);
8584

8685
for (const cmd of ToolPluginSubCommandsSchema.keyof().options) {
87-
program.addCommand(await getPluginSubCommand(cmd));
86+
const command = await getPluginSubCommand(cmd);
87+
if (command) {
88+
program.addCommand(command);
89+
}
8890
}
89-
91+
program.addCommand(
92+
new Command('help').action(() => {
93+
logger.info(program.help());
94+
})
95+
);
9096
// Default action to catch unknown commands.
91-
program.action((_, { args }: { args: string[] }) => {
92-
logger.error(`"${clc.bold(args[0])}" is not a known Genkit command.`);
97+
program.action(() => {
98+
// print help
99+
logger.info(program.help());
93100
});
94101

95102
await program.parseAsync();

genkit-tools/cli/src/commands/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const CONFIG_TAGS: Record<
4343
export const config = new Command('config');
4444

4545
config
46+
.description('set development environment configuration')
4647
.command('get')
4748
.argument('<tag>', `The config tag to get. One of [${readableTagsHint()}]`)
4849
.action((tag) => {

genkit-tools/cli/src/commands/eval-extract-data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ interface EvalDatasetOptions {
3333

3434
/** Command to extract evaluation data. */
3535
export const evalExtractData = new Command('eval:extractData')
36+
.description('extract evaludation data for a given flow from the trace store')
3637
.argument('<flowName>', 'name of the flow to run')
3738
.option('--env <env>', 'environment (dev/prod)', 'dev')
3839
.option(

genkit-tools/cli/src/commands/eval-flow.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ const EVAL_FLOW_SCHEMA = '{samples: Array<{input: any; reference?: any;}>}';
5656

5757
/** Command to run a flow and evaluate the output */
5858
export const evalFlow = new Command('eval:flow')
59+
.description(
60+
'evaluate a flow against configured evaluators using provided data as input'
61+
)
5962
.argument('<flowName>', 'Name of the flow to run')
6063
.argument('[data]', 'JSON data to use to start the flow')
6164
.option('--input <filename>', 'JSON batch data to use to run the flow')

genkit-tools/cli/src/commands/eval-run.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ interface EvalRunOptions {
4141
}
4242
/** Command to run evaluation on a dataset. */
4343
export const evalRun = new Command('eval:run')
44+
.description('evaluate provided dataset against configured evaluators')
4445
.argument(
4546
'<dataset>',
4647
'Dataset to evaluate on (currently only supports JSON)'

genkit-tools/cli/src/commands/flow-batch-run.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ interface FlowBatchRunOptions {
3636

3737
/** Command to run flows with batch input. */
3838
export const flowBatchRun = new Command('flow:batchRun')
39+
.description(
40+
'batch run a flow using provided set of data from a file as input'
41+
)
3942
.argument('<flowName>', 'name of the flow to run')
4043
.argument('<inputFileName>', 'JSON batch data to use to run the flow')
4144
.option('-w, --wait', 'Wait for the flow to complete', false)

genkit-tools/cli/src/commands/flow-resume.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { Command } from 'commander';
2020

2121
/** Command to start GenKit server, optionally without static file serving */
2222
export const flowResume = new Command('flow:resume')
23+
.description('resume an interrupted flow (experimental)')
2324
.argument('<flowName>', 'name of the flow to resume')
2425
.argument('<flowId>', 'ID of the flow to resume')
2526
.argument('<data>', 'JSON data to use to resume the flow')

genkit-tools/cli/src/commands/flow-run.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface FlowRunOptions {
3232

3333
/** Command to start GenKit server, optionally without static file serving */
3434
export const flowRun = new Command('flow:run')
35+
.description('run a flow using provided data as input')
3536
.argument('<flowName>', 'name of the flow to run')
3637
.argument('[data]', 'JSON data to use to start the flow')
3738
.option('-w, --wait', 'Wait for the flow to complete', false)

genkit-tools/cli/src/commands/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ const sampleTemplatePaths: Record<Platform, string> = {
154154
const supportedRuntimes: Runtime[] = ['node'];
155155

156156
export const init = new Command('init')
157-
.description('Initialize a project directory with Genkit')
157+
.description('initialize a project directory with Genkit')
158158
.option(
159159
'-p, --platform <platform>',
160160
'Deployment platform (firebase, googlecloud, or nodejs)'

genkit-tools/cli/src/commands/plugins.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function getPluginCommands(): Promise<Command[]> {
3434
/** Gets special-case commands for plugins in the config file. */
3535
export async function getPluginSubCommand(
3636
commandString: SpecialAction
37-
): Promise<Command> {
37+
): Promise<Command | undefined> {
3838
const config = await findToolsConfig();
3939
const actions = (config?.cliPlugins || [])
4040
.filter((p) => !!p.subCommands?.[commandString])
@@ -48,12 +48,7 @@ export async function getPluginSubCommand(
4848
);
4949

5050
if (!actions.length) {
51-
return command.action(() => {
52-
logger.error(
53-
`No plugins installed that support ${commandString}. Add a supported ` +
54-
`plugin to your ${clc.bold('genkit-tools.conf.js')} file.`
55-
);
56-
});
51+
return undefined;
5752
}
5853

5954
for (const a of actions) {

0 commit comments

Comments
 (0)