CenaForge: primeira versão pública
Gerador de vídeos narrativos (Godot + FFmpeg), painel Next.js, serviço de voz, Clipador de lives e Publicador para YouTube, TikTok e Instagram. Inclui a leitura das visualizações dos posts para o Dashboard e o botão "Publicar no <rede>" nos cartões das publicações. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// Leitura mínima de argumentos: --chave valor, --chave=valor e --flag.
|
||||
// Um "--" solto (que o pnpm pode repassar) é ignorado.
|
||||
|
||||
export type ParsedArgs = { positional: string[]; options: Map<string, string | true> };
|
||||
|
||||
export function parseArgs(argv: string[]): ParsedArgs {
|
||||
const positional: string[] = [];
|
||||
const options = new Map<string, string | true>();
|
||||
for (let i = 0; i < argv.length; i++) {
|
||||
const arg = argv[i];
|
||||
if (arg === "--") continue;
|
||||
if (arg.startsWith("--")) {
|
||||
const body = arg.slice(2);
|
||||
const eq = body.indexOf("=");
|
||||
if (eq >= 0) {
|
||||
options.set(body.slice(0, eq), body.slice(eq + 1));
|
||||
} else if (i + 1 < argv.length && !argv[i + 1].startsWith("--")) {
|
||||
options.set(body, argv[++i]);
|
||||
} else {
|
||||
options.set(body, true);
|
||||
}
|
||||
} else {
|
||||
positional.push(arg);
|
||||
}
|
||||
}
|
||||
return { positional, options };
|
||||
}
|
||||
|
||||
export function stringOption(args: ParsedArgs, name: string): string | undefined {
|
||||
const value = args.options.get(name);
|
||||
if (value === undefined) return undefined;
|
||||
if (value === true) throw new UsageError(`--${name} exige um valor`);
|
||||
return value;
|
||||
}
|
||||
|
||||
export function numberOption(args: ParsedArgs, name: string): number | undefined {
|
||||
const raw = stringOption(args, name);
|
||||
if (raw === undefined) return undefined;
|
||||
const value = Number(raw);
|
||||
if (!Number.isFinite(value)) throw new UsageError(`--${name} precisa ser número (recebido "${raw}")`);
|
||||
return value;
|
||||
}
|
||||
|
||||
export class UsageError extends Error {}
|
||||
Reference in New Issue
Block a user