mirror of
https://github.com/modelstudioai/cli.git
synced 2026-09-14 19:49:23 +08:00
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { expect, test } from "vite-plus/test";
|
|
import { ExitCode, GLOBAL_OPTIONS } from "bailian-cli-core";
|
|
import { parseFlags } from "../src/args.ts";
|
|
|
|
const IMAGE_GENERATE_OPTIONS = [
|
|
{ flag: "--prompt <text>", description: "Image description", required: true },
|
|
{ flag: "--model <model>", description: "Model ID" },
|
|
{ flag: "--watermark <bool>", description: "Enable watermark (true/false). Default: true." },
|
|
];
|
|
|
|
test("parseFlags rejects unknown long flags", () => {
|
|
expect(() =>
|
|
parseFlags(["--prompt", "cat", "--xxxx", "a"], [...GLOBAL_OPTIONS, ...IMAGE_GENERATE_OPTIONS]),
|
|
).toThrowError(
|
|
expect.objectContaining({
|
|
name: "BailianError",
|
|
exitCode: ExitCode.USAGE,
|
|
message: expect.stringContaining('Unknown flag "--xxxx"'),
|
|
}),
|
|
);
|
|
});
|
|
|
|
test("parseFlags rejects unknown flags with = syntax", () => {
|
|
expect(() =>
|
|
parseFlags(
|
|
["--prompt=cat", "--unknown-flag=yes"],
|
|
[...GLOBAL_OPTIONS, ...IMAGE_GENERATE_OPTIONS],
|
|
),
|
|
).toThrow(/Unknown flag "--unknown-flag"/);
|
|
});
|
|
|
|
test("parseFlags accepts defined command and global flags", () => {
|
|
const flags = parseFlags(
|
|
["--quiet", "--prompt", "cat", "--watermark", "false"],
|
|
[...GLOBAL_OPTIONS, ...IMAGE_GENERATE_OPTIONS],
|
|
);
|
|
expect(flags.quiet).toBe(true);
|
|
expect(flags.prompt).toBe("cat");
|
|
expect(flags.watermark).toBe("false");
|
|
});
|