Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cli cleanup: show help when no command provided, hide login/deploy unless plugins installed #105

Merged
merged 4 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions genkit-tools/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
notifyAnalyticsIfFirstRun,
record,
} from '@genkit-ai/tools-common/utils';
import * as clc from 'colorette';
import { Command, program } from 'commander';
import { config } from './commands/config';
import { evalExtractData } from './commands/eval-extract-data';
Expand Down Expand Up @@ -57,7 +56,7 @@ const commands: Command[] = [
export async function startCLI(): Promise<void> {
program
.name('genkit')
.description('Google Genkit CLI')
.description('Firebase Genkit CLI')
.version(version)
.hook('preAction', async (_, actionCommand) => {
await notifyAnalyticsIfFirstRun();
Expand All @@ -84,12 +83,20 @@ export async function startCLI(): Promise<void> {
for (const command of await getPluginCommands()) program.addCommand(command);

for (const cmd of ToolPluginSubCommandsSchema.keyof().options) {
program.addCommand(await getPluginSubCommand(cmd));
const command = await getPluginSubCommand(cmd);
if (command) {
program.addCommand(command);
}
}

program.addCommand(
new Command('help').action(() => {
logger.info(program.help());
})
);
// Default action to catch unknown commands.
program.action((_, { args }: { args: string[] }) => {
logger.error(`"${clc.bold(args[0])}" is not a known Genkit command.`);
program.action(() => {
// print help
logger.info(program.help());
});

await program.parseAsync();
Expand Down
1 change: 1 addition & 0 deletions genkit-tools/cli/src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const CONFIG_TAGS: Record<
export const config = new Command('config');

config
.description('set development environment configuration')
.command('get')
.argument('<tag>', `The config tag to get. One of [${readableTagsHint()}]`)
.action((tag) => {
Expand Down
1 change: 1 addition & 0 deletions genkit-tools/cli/src/commands/eval-extract-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface EvalDatasetOptions {

/** Command to extract evaluation data. */
export const evalExtractData = new Command('eval:extractData')
.description('extract evaludation data for a given flow from the trace store')
.argument('<flowName>', 'name of the flow to run')
.option('--env <env>', 'environment (dev/prod)', 'dev')
.option(
Expand Down
3 changes: 3 additions & 0 deletions genkit-tools/cli/src/commands/eval-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ const EVAL_FLOW_SCHEMA = '{samples: Array<{input: any; reference?: any;}>}';

/** Command to run a flow and evaluate the output */
export const evalFlow = new Command('eval:flow')
.description(
'evaluate a flow against configured evaluators using provided data as input'
)
.argument('<flowName>', 'Name of the flow to run')
.argument('[data]', 'JSON data to use to start the flow')
.option('--input <filename>', 'JSON batch data to use to run the flow')
Expand Down
1 change: 1 addition & 0 deletions genkit-tools/cli/src/commands/eval-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface EvalRunOptions {
}
/** Command to run evaluation on a dataset. */
export const evalRun = new Command('eval:run')
.description('evaluate provided dataset against configured evaluators')
.argument(
'<dataset>',
'Dataset to evaluate on (currently only supports JSON)'
Expand Down
3 changes: 3 additions & 0 deletions genkit-tools/cli/src/commands/flow-batch-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ interface FlowBatchRunOptions {

/** Command to run flows with batch input. */
export const flowBatchRun = new Command('flow:batchRun')
.description(
'batch run a flow using provided set of data from a file as input'
)
.argument('<flowName>', 'name of the flow to run')
.argument('<inputFileName>', 'JSON batch data to use to run the flow')
.option('-w, --wait', 'Wait for the flow to complete', false)
Expand Down
1 change: 1 addition & 0 deletions genkit-tools/cli/src/commands/flow-resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Command } from 'commander';

/** Command to start GenKit server, optionally without static file serving */
export const flowResume = new Command('flow:resume')
.description('resume an interrupted flow (experimental)')
.argument('<flowName>', 'name of the flow to resume')
.argument('<flowId>', 'ID of the flow to resume')
.argument('<data>', 'JSON data to use to resume the flow')
Expand Down
1 change: 1 addition & 0 deletions genkit-tools/cli/src/commands/flow-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface FlowRunOptions {

/** Command to start GenKit server, optionally without static file serving */
export const flowRun = new Command('flow:run')
.description('run a flow using provided data as input')
.argument('<flowName>', 'name of the flow to run')
.argument('[data]', 'JSON data to use to start the flow')
.option('-w, --wait', 'Wait for the flow to complete', false)
Expand Down
2 changes: 1 addition & 1 deletion genkit-tools/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const sampleTemplatePaths: Record<Platform, string> = {
const supportedRuntimes: Runtime[] = ['node'];

export const init = new Command('init')
.description('Initialize a project directory with Genkit')
.description('initialize a project directory with Genkit')
.option(
'-p, --platform <platform>',
'Deployment platform (firebase, googlecloud, or nodejs)'
Expand Down
9 changes: 2 additions & 7 deletions genkit-tools/cli/src/commands/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function getPluginCommands(): Promise<Command[]> {
/** Gets special-case commands for plugins in the config file. */
export async function getPluginSubCommand(
commandString: SpecialAction
): Promise<Command> {
): Promise<Command | undefined> {
const config = await findToolsConfig();
const actions = (config?.cliPlugins || [])
.filter((p) => !!p.subCommands?.[commandString])
Expand All @@ -48,12 +48,7 @@ export async function getPluginSubCommand(
);

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

for (const a of actions) {
Expand Down
1 change: 1 addition & 0 deletions genkit-tools/cli/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface StartOptions {

/** Command to start GenKit server, optionally without static file serving */
export const start = new Command('start')
.description('run the app in dev mode and start a Developer UI')
.option(
'-x, --headless',
'Do not serve static UI files (for development)',
Expand Down
Loading