chore: init clean tree
This commit is contained in:
104
src/renderer/cli.ts
Normal file
104
src/renderer/cli.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
export type CliConfig = {
|
||||
rendererId?: string;
|
||||
debugGlobalHud: boolean;
|
||||
debugRendererHud: boolean;
|
||||
crashRecoverySession?: string | true;
|
||||
errorScreenRequested?: boolean;
|
||||
errorScreenMessage?: string;
|
||||
errorScreenTitle?: string;
|
||||
errorScreenHint?: string;
|
||||
debugLogFile?: string;
|
||||
helpRequested: boolean;
|
||||
};
|
||||
|
||||
export function parseCli(argv: string[]): CliConfig {
|
||||
// Bun passes: [bunPath, scriptPath, ...]
|
||||
const args = argv.slice(2);
|
||||
const config: CliConfig = {
|
||||
debugGlobalHud: false,
|
||||
debugRendererHud: false,
|
||||
helpRequested: false
|
||||
};
|
||||
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i] ?? "";
|
||||
if (arg === "--help" || arg === "-h") {
|
||||
config.helpRequested = true;
|
||||
continue;
|
||||
}
|
||||
if (arg === "--renderer" && args[i + 1] && !args[i + 1]!.startsWith("--")) {
|
||||
config.rendererId = args[i + 1]!;
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--renderer=")) {
|
||||
config.rendererId = arg.split("=")[1];
|
||||
continue;
|
||||
}
|
||||
if (arg === "--debug") {
|
||||
config.debugGlobalHud = true;
|
||||
config.debugRendererHud = true;
|
||||
continue;
|
||||
}
|
||||
if (arg === "--debug-global") {
|
||||
config.debugGlobalHud = true;
|
||||
continue;
|
||||
}
|
||||
if (arg === "--debug-renderer") {
|
||||
config.debugRendererHud = true;
|
||||
continue;
|
||||
}
|
||||
if (arg === "--error-screen") {
|
||||
config.errorScreenRequested = true;
|
||||
if (args[i + 1] && !args[i + 1]!.startsWith("--")) {
|
||||
config.errorScreenMessage = args[i + 1]!;
|
||||
i += 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--error-screen=")) {
|
||||
config.errorScreenRequested = true;
|
||||
config.errorScreenMessage = arg.split("=").slice(1).join("=");
|
||||
continue;
|
||||
}
|
||||
if (arg === "--error-title" && args[i + 1] && !args[i + 1]!.startsWith("--")) {
|
||||
config.errorScreenTitle = args[i + 1]!;
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--error-title=")) {
|
||||
config.errorScreenTitle = arg.split("=").slice(1).join("=");
|
||||
continue;
|
||||
}
|
||||
if (arg === "--error-hint" && args[i + 1] && !args[i + 1]!.startsWith("--")) {
|
||||
config.errorScreenHint = args[i + 1]!;
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--error-hint=")) {
|
||||
config.errorScreenHint = arg.split("=").slice(1).join("=");
|
||||
continue;
|
||||
}
|
||||
if (arg === "--debug-log-file" && args[i + 1] && !args[i + 1]!.startsWith("--")) {
|
||||
config.debugLogFile = args[i + 1]!;
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--debug-log-file=")) {
|
||||
config.debugLogFile = arg.split("=").slice(1).join("=");
|
||||
continue;
|
||||
}
|
||||
if (arg === "--crash-recovery") {
|
||||
const maybeSession = args[i + 1];
|
||||
if (maybeSession && !maybeSession.startsWith("--")) {
|
||||
config.crashRecoverySession = maybeSession;
|
||||
i += 1;
|
||||
} else {
|
||||
config.crashRecoverySession = "Hyprland";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
Reference in New Issue
Block a user