@flatkey-ai/cli 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cli.js +42 -6
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -15,6 +15,28 @@ const COMMANDS = new Set([
|
|
|
15
15
|
]);
|
|
16
16
|
|
|
17
17
|
const GROUP_ACTIONS = new Set(["audio", "auth", "image", "text", "video"]);
|
|
18
|
+
const GLOBAL_OPTIONS = new Set(["api_key", "base_url", "dry_run", "help", "json", "output", "out"]);
|
|
19
|
+
const COMMAND_OPTIONS = {
|
|
20
|
+
"audio generate": new Set(["model", "prompt", "similarity_boost", "stability", "style", "voice_id"]),
|
|
21
|
+
"audio music": new Set(["music_length_ms", "prompt"]),
|
|
22
|
+
"audio sfx": new Set(["duration", "prompt"]),
|
|
23
|
+
"audio voices": new Set([]),
|
|
24
|
+
"auth status": new Set([]),
|
|
25
|
+
credits: new Set([]),
|
|
26
|
+
help: new Set(["ai", "command"]),
|
|
27
|
+
image: new Set([]),
|
|
28
|
+
"image generate": new Set(["model", "n", "prompt", "quality", "size"]),
|
|
29
|
+
login: new Set(["console_url", "no_open", "open"]),
|
|
30
|
+
logout: new Set([]),
|
|
31
|
+
models: new Set(["type"]),
|
|
32
|
+
onboard: new Set(["api_key"]),
|
|
33
|
+
status: new Set([]),
|
|
34
|
+
text: new Set([]),
|
|
35
|
+
"text generate": new Set(["model", "prompt"]),
|
|
36
|
+
version: new Set([]),
|
|
37
|
+
video: new Set([]),
|
|
38
|
+
"video generate": new Set(["aspect", "duration", "fps", "model", "prompt", "ratio", "resolution"]),
|
|
39
|
+
};
|
|
18
40
|
|
|
19
41
|
export function parseArgv(argv) {
|
|
20
42
|
const [group, maybeAction, ...rest] = argv;
|
|
@@ -31,11 +53,11 @@ export function parseArgv(argv) {
|
|
|
31
53
|
throw new Error(`Unknown command: ${group}`);
|
|
32
54
|
}
|
|
33
55
|
if (group === "help" && maybeAction && !maybeAction.startsWith("--")) {
|
|
34
|
-
return {
|
|
56
|
+
return validateCommandOptions({
|
|
35
57
|
group: "help",
|
|
36
58
|
action: undefined,
|
|
37
59
|
options: { command: maybeAction, ...parseOptions(rest) },
|
|
38
|
-
};
|
|
60
|
+
});
|
|
39
61
|
}
|
|
40
62
|
|
|
41
63
|
const hasAction = GROUP_ACTIONS.has(group);
|
|
@@ -50,21 +72,21 @@ export function parseArgv(argv) {
|
|
|
50
72
|
const hasHelpOption = optionTokens.some((token) => token === "--help" || token === "-h")
|
|
51
73
|
|| (optionTokens.length === 1 && optionTokens[0] === "help");
|
|
52
74
|
if (hasHelpOption) {
|
|
53
|
-
return {
|
|
75
|
+
return validateCommandOptions({
|
|
54
76
|
group,
|
|
55
77
|
action,
|
|
56
78
|
options: {
|
|
57
79
|
...parseOptions(optionTokens.filter((token) => token !== "help" && token !== "--help" && token !== "-h")),
|
|
58
80
|
help: true,
|
|
59
81
|
},
|
|
60
|
-
};
|
|
82
|
+
});
|
|
61
83
|
}
|
|
62
84
|
|
|
63
|
-
return {
|
|
85
|
+
return validateCommandOptions({
|
|
64
86
|
group,
|
|
65
87
|
action,
|
|
66
88
|
options: parseOptions(optionTokens),
|
|
67
|
-
};
|
|
89
|
+
});
|
|
68
90
|
}
|
|
69
91
|
|
|
70
92
|
function isHelpToken(token) {
|
|
@@ -99,6 +121,20 @@ function parseOptions(tokens) {
|
|
|
99
121
|
return options;
|
|
100
122
|
}
|
|
101
123
|
|
|
124
|
+
function validateCommandOptions(command) {
|
|
125
|
+
const key = command.action ? `${command.group} ${command.action}` : command.group;
|
|
126
|
+
const allowed = COMMAND_OPTIONS[key] ?? new Set();
|
|
127
|
+
for (const option of Object.keys(command.options)) {
|
|
128
|
+
if (GLOBAL_OPTIONS.has(option) || allowed.has(option)) continue;
|
|
129
|
+
const flag = `--${option.replaceAll("_", "-")}`;
|
|
130
|
+
const helpCommand = command.action
|
|
131
|
+
? `flatkey ${command.group} ${command.action} --help`
|
|
132
|
+
: `flatkey ${command.group} --help`;
|
|
133
|
+
throw new Error(`Unknown option ${flag} for flatkey ${key}. Run \`${helpCommand}\` to see supported options.`);
|
|
134
|
+
}
|
|
135
|
+
return command;
|
|
136
|
+
}
|
|
137
|
+
|
|
102
138
|
export async function main(argv) {
|
|
103
139
|
const command = parseArgv(argv);
|
|
104
140
|
if (command.options.help) {
|