Skip to content

Commit bd4b0ad

Browse files
committed
fix(runtime): tailor root help to product entrypoints
- render auth flag sections only for auth domains used by registered commands - make quick-start prompts opt-in through createCli options - keep the existing quick-start prompts wired only for bl
1 parent 2debfdb commit bd4b0ad

4 files changed

Lines changed: 66 additions & 26 deletions

File tree

packages/cli/src/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ import { createCli } from "bailian-cli-runtime";
22
import { commands } from "./commands.ts";
33
import pkg from "../package.json" with { type: "json" };
44

5+
const quickStartTasks = [
6+
"Help me generate a set of Amazon e-commerce main images for baseball caps (white background + lifestyle shots + model wear shots)",
7+
"Help me generate a 3-minute humorous crosstalk audio clip",
8+
"Help me generate a Little Red Riding Hood picture-book PDF (with illustrations)",
9+
"Help me analyze this video and write a Xiaohongshu-style post",
10+
] as const;
11+
512
void createCli(commands, {
613
binName: "bl",
714
version: pkg.version,
815
clientName: "bailian-cli",
916
npmPackage: "bailian-cli",
17+
quickStartTasks,
1018
}).run();

packages/runtime/src/create-cli.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export interface CliOptions {
4040
clientName: string;
4141
/** npm package name for self-update (e.g. "bailian-cli", "bailian-cli-rag"). */
4242
npmPackage: string;
43+
/** Root-help suggestions shown after credentials are configured. */
44+
quickStartTasks?: readonly string[];
4345
}
4446

4547
export interface Cli {
@@ -112,8 +114,11 @@ export function createCli(commands: Record<string, AnyCommand>, opts: CliOptions
112114
} catch {
113115
/* unparseable global flags on the bare invocation — fall through to welcome */
114116
}
115-
if (hasKey) printQuickStart();
116-
else printWelcomeBanner(binName);
117+
if (hasKey) {
118+
if (opts.quickStartTasks?.length) printQuickStart(opts.quickStartTasks);
119+
} else {
120+
printWelcomeBanner(binName);
121+
}
117122
}
118123

119124
async function dispatch(argv: string[]): Promise<void> {

packages/runtime/src/output/banner.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { API_KEY_PAGE } from "../urls.ts";
22
import { ansi } from "./color.ts";
33

4-
const QUICK_START_TASKS = [
5-
"Help me generate a set of Amazon e-commerce main images for baseball caps (white background + lifestyle shots + model wear shots)",
6-
"Help me generate a 3-minute humorous crosstalk audio clip",
7-
"Help me generate a Little Red Riding Hood picture-book PDF (with illustrations)",
8-
"Help me analyze this video and write a Xiaohongshu-style post",
9-
];
10-
114
export function printWelcomeBanner(cliName: string): void {
125
const color = ansi(process.stderr);
136
process.stderr.write(`\n Welcome to ${color.purple("Bailian")} CLI!\n\n`);
@@ -16,10 +9,10 @@ export function printWelcomeBanner(cliName: string): void {
169
process.stderr.write(` 2. Login: ${cliName} auth login --api-key <your-key>\n\n`);
1710
}
1811

19-
export function printQuickStart(): void {
12+
export function printQuickStart(tasks: readonly string[]): void {
2013
const color = ansi(process.stderr);
2114
process.stderr.write("\n🎯 Try these with your AI coding assistant:\n\n");
22-
QUICK_START_TASKS.forEach((task, i) => {
15+
tasks.forEach((task, i) => {
2316
process.stderr.write(`${color.dim(String(i + 1))} ${task}\n`);
2417
});
2518
process.stderr.write("\n");

packages/runtime/src/registry.ts

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AnyCommand, FlagDef } from "bailian-cli-core";
1+
import type { AnyCommand, AuthRequirement, FlagDef, FlagsDef } from "bailian-cli-core";
22
import { UsageError } from "bailian-cli-core";
33
import {
44
CONSOLE_AUTH_FLAGS,
@@ -42,6 +42,7 @@ export class CommandRegistry {
4242
private root: CommandNode = { children: new Map() };
4343
/** Binary name shown in usage/help/error strings (e.g. "bl", "rag"). */
4444
private readonly cliName: string;
45+
private readonly authRequirements = new Set<AuthRequirement>();
4546

4647
constructor(commands: Record<string, AnyCommand>, cliName: string) {
4748
this.cliName = cliName;
@@ -67,6 +68,7 @@ export class CommandRegistry {
6768
node = node.children.get(part)!;
6869
}
6970
node.command = command;
71+
this.authRequirements.add(command.auth);
7072
}
7173

7274
getAllCommands(): AnyCommand[] {
@@ -176,7 +178,7 @@ export class CommandRegistry {
176178
}
177179

178180
private buildFlagLines(
179-
defs: Record<string, FlagDef>,
181+
defs: FlagsDef,
180182
a: (s: string) => string,
181183
d: (s: string) => string,
182184
): string {
@@ -188,6 +190,19 @@ export class CommandRegistry {
188190
return lines.map((l) => ` ${a(l.flag.padEnd(maxLen + 2))} ${d(l.desc)}`).join("\n");
189191
}
190192

193+
private buildAuthFlagSection(
194+
auth: AuthRequirement,
195+
label: string,
196+
scope: string,
197+
defs: FlagsDef,
198+
b: (s: string) => string,
199+
a: (s: string) => string,
200+
d: (s: string) => string,
201+
): string | null {
202+
if (!this.authRequirements.has(auth)) return null;
203+
return `${b(label)} ${d(scope)}\n${this.buildFlagLines(defs, a, d)}`;
204+
}
205+
191206
// Color helpers — no-ops when output is not a TTY.
192207
private bold = (s: string, out: NodeJS.WriteStream) => ansi(out).bold(s);
193208
private accent = (s: string, out: NodeJS.WriteStream) => ansi(out).accent(s);
@@ -268,9 +283,37 @@ ${d(` ${this.cliName} pipeline run workflow.yaml --dry-run --output json`)}
268283

269284
const commandLines = this.buildResourceLines(a, d);
270285
const globalFlagLines = this.buildFlagLines(GLOBAL_FLAGS, a, d);
271-
const modelFlagLines = this.buildFlagLines(MODEL_AUTH_FLAGS, a, d);
272-
const consoleFlagLines = this.buildFlagLines(CONSOLE_AUTH_FLAGS, a, d);
273-
const openapiFlagLines = this.buildFlagLines(OPENAPI_AUTH_FLAGS, a, d);
286+
const authFlagSections = [
287+
this.buildAuthFlagSection(
288+
"apiKey",
289+
"Model Auth Flags:",
290+
"(model-domain commands)",
291+
MODEL_AUTH_FLAGS,
292+
b,
293+
a,
294+
d,
295+
),
296+
this.buildAuthFlagSection(
297+
"console",
298+
"Console Auth Flags:",
299+
"(console-domain commands)",
300+
CONSOLE_AUTH_FLAGS,
301+
b,
302+
a,
303+
d,
304+
),
305+
this.buildAuthFlagSection(
306+
"openapi",
307+
"OpenAPI Auth Flags:",
308+
"(openapi-domain commands)",
309+
OPENAPI_AUTH_FLAGS,
310+
b,
311+
a,
312+
d,
313+
),
314+
]
315+
.filter((section): section is string => section !== null)
316+
.join("\n\n");
274317

275318
out.write(`
276319
${b("Usage:")} ${this.cliName} <resource> <command> [flags]
@@ -281,16 +324,7 @@ ${commandLines}
281324
${b("Global Flags:")}
282325
${globalFlagLines}
283326
284-
${b("Model Auth Flags:")} ${d("(model-domain commands)")}
285-
${modelFlagLines}
286-
287-
${b("Console Auth Flags:")} ${d("(console-domain commands)")}
288-
${consoleFlagLines}
289-
290-
${b("OpenAPI Auth Flags:")} ${d("(openapi-domain commands)")}
291-
${openapiFlagLines}
292-
293-
${b("Getting Help:")}
327+
${authFlagSections ? `${authFlagSections}\n\n` : ""}${b("Getting Help:")}
294328
${d("Add --help after any command to see its full list of flags, defaults,")}
295329
${d("and usage examples. For example:")} ${this.cliName} ${this.helpExample()} --help
296330
`);

0 commit comments

Comments
 (0)