mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-25 08:48:08 +02:00
feat: expose runtime management commands
This commit is contained in:
parent
50811716c2
commit
f87b58ffb0
5 changed files with 137 additions and 1 deletions
73
packages/cli/src/commands/runtime-commands.ts
Normal file
73
packages/cli/src/commands/runtime-commands.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import { type Command, Option } from '@commander-js/extra-typings';
|
||||
import type { KtxCliCommandContext } from '../cli-program.js';
|
||||
import type { KtxRuntimeArgs } from '../runtime.js';
|
||||
|
||||
type RuntimeFeature = Extract<KtxRuntimeArgs, { command: 'install' }>['feature'];
|
||||
|
||||
const runtimeFeatureOption = new Option('--feature <feature>', 'Runtime feature level')
|
||||
.choices(['core', 'local-embeddings'])
|
||||
.default('core');
|
||||
|
||||
async function runRuntimeArgs(context: KtxCliCommandContext, args: KtxRuntimeArgs): Promise<void> {
|
||||
const runner = context.deps.runtime ?? (await import('../runtime.js')).runKtxRuntime;
|
||||
context.setExitCode(await runner(args, context.io));
|
||||
}
|
||||
|
||||
export function registerRuntimeCommands(program: Command, context: KtxCliCommandContext): void {
|
||||
const runtime = program
|
||||
.command('runtime')
|
||||
.description('Install, inspect, and prune the KTX-managed Python runtime')
|
||||
.showHelpAfterError();
|
||||
|
||||
runtime
|
||||
.command('install')
|
||||
.description('Install the bundled Python runtime wheel into the managed runtime')
|
||||
.addOption(runtimeFeatureOption)
|
||||
.option('--force', 'Reinstall even when the runtime already looks ready', false)
|
||||
.action(async (options: { feature: RuntimeFeature; force?: boolean }) => {
|
||||
await runRuntimeArgs(context, {
|
||||
command: 'install',
|
||||
cliVersion: context.packageInfo.version,
|
||||
feature: options.feature,
|
||||
force: options.force === true,
|
||||
});
|
||||
});
|
||||
|
||||
runtime
|
||||
.command('status')
|
||||
.description('Show managed Python runtime status')
|
||||
.option('--json', 'Print JSON output', false)
|
||||
.action(async (options: { json?: boolean }) => {
|
||||
await runRuntimeArgs(context, {
|
||||
command: 'status',
|
||||
cliVersion: context.packageInfo.version,
|
||||
json: options.json === true,
|
||||
});
|
||||
});
|
||||
|
||||
runtime
|
||||
.command('doctor')
|
||||
.description('Check managed Python runtime prerequisites and installation')
|
||||
.option('--json', 'Print JSON output', false)
|
||||
.action(async (options: { json?: boolean }) => {
|
||||
await runRuntimeArgs(context, {
|
||||
command: 'doctor',
|
||||
cliVersion: context.packageInfo.version,
|
||||
json: options.json === true,
|
||||
});
|
||||
});
|
||||
|
||||
runtime
|
||||
.command('prune')
|
||||
.description('Remove stale managed Python runtimes for older CLI versions')
|
||||
.option('--dry-run', 'List stale runtimes without deleting them', false)
|
||||
.option('--yes', 'Confirm deletion of stale runtime directories', false)
|
||||
.action(async (options: { dryRun?: boolean; yes?: boolean }) => {
|
||||
await runRuntimeArgs(context, {
|
||||
command: 'prune',
|
||||
cliVersion: context.packageInfo.version,
|
||||
dryRun: options.dryRun === true,
|
||||
yes: options.yes === true,
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue