mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
chore: add project management metadata and remaining repository files
This commit is contained in:
61
launcher/config.ts
Normal file
61
launcher/config.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { fail } from './log.js';
|
||||
import type {
|
||||
Args,
|
||||
LauncherJellyfinConfig,
|
||||
LauncherYoutubeSubgenConfig,
|
||||
LogLevel,
|
||||
PluginRuntimeConfig,
|
||||
} from './types.js';
|
||||
import {
|
||||
applyInvocationsToArgs,
|
||||
applyRootOptionsToArgs,
|
||||
createDefaultArgs,
|
||||
} from './config/args-normalizer.js';
|
||||
import { parseCliPrograms, resolveTopLevelCommand } from './config/cli-parser-builder.js';
|
||||
import { parseLauncherJellyfinConfig } from './config/jellyfin-config.js';
|
||||
import { readPluginRuntimeConfig as readPluginRuntimeConfigValue } from './config/plugin-runtime-config.js';
|
||||
import { readLauncherMainConfigObject } from './config/shared-config-reader.js';
|
||||
import { parseLauncherYoutubeSubgenConfig } from './config/youtube-subgen-config.js';
|
||||
|
||||
export function loadLauncherYoutubeSubgenConfig(): LauncherYoutubeSubgenConfig {
|
||||
const root = readLauncherMainConfigObject();
|
||||
if (!root) return {};
|
||||
return parseLauncherYoutubeSubgenConfig(root);
|
||||
}
|
||||
|
||||
export function loadLauncherJellyfinConfig(): LauncherJellyfinConfig {
|
||||
const root = readLauncherMainConfigObject();
|
||||
if (!root) return {};
|
||||
return parseLauncherJellyfinConfig(root);
|
||||
}
|
||||
|
||||
export function readPluginRuntimeConfig(logLevel: LogLevel): PluginRuntimeConfig {
|
||||
return readPluginRuntimeConfigValue(logLevel);
|
||||
}
|
||||
|
||||
export function parseArgs(
|
||||
argv: string[],
|
||||
scriptName: string,
|
||||
launcherConfig: LauncherYoutubeSubgenConfig,
|
||||
): Args {
|
||||
const topLevelCommand = resolveTopLevelCommand(argv);
|
||||
const parsed = createDefaultArgs(launcherConfig);
|
||||
|
||||
if (topLevelCommand && (topLevelCommand.name === 'app' || topLevelCommand.name === 'bin')) {
|
||||
parsed.appPassthrough = true;
|
||||
parsed.appArgs = argv.slice(topLevelCommand.index + 1);
|
||||
return parsed;
|
||||
}
|
||||
|
||||
let cliResult: ReturnType<typeof parseCliPrograms>;
|
||||
try {
|
||||
cliResult = parseCliPrograms(argv, scriptName);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
fail(message);
|
||||
}
|
||||
|
||||
applyRootOptionsToArgs(parsed, cliResult.options, cliResult.rootTarget);
|
||||
applyInvocationsToArgs(parsed, cliResult.invocations);
|
||||
return parsed;
|
||||
}
|
||||
Reference in New Issue
Block a user