mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-10 08:05:14 +02:00
refactor: share managed runtime install policy parsing
This commit is contained in:
parent
f9806e69c7
commit
f30f4d688d
3 changed files with 31 additions and 12 deletions
|
|
@ -6,7 +6,7 @@ import {
|
|||
resolveCommandProjectDir,
|
||||
} from '../cli-program.js';
|
||||
import { slQueryCommandSchema } from '../command-schemas.js';
|
||||
import type { KtxManagedPythonInstallPolicy } from '../managed-python-command.js';
|
||||
import { runtimeInstallPolicyFromFlags } from '../managed-python-command.js';
|
||||
import type { KtxSlArgs } from '../sl.js';
|
||||
import { profileMark } from '../startup-profile.js';
|
||||
|
||||
|
|
@ -33,16 +33,6 @@ function collectOrderBy(
|
|||
return [...previous, parseOrderBy(value)];
|
||||
}
|
||||
|
||||
function runtimeInstallPolicy(options: { yes?: boolean; input?: boolean }): KtxManagedPythonInstallPolicy {
|
||||
if (options.yes === true && options.input === false) {
|
||||
throw new Error('Choose only one runtime install mode: --yes or --no-input');
|
||||
}
|
||||
if (options.yes === true) {
|
||||
return 'auto';
|
||||
}
|
||||
return options.input === false ? 'never' : 'prompt';
|
||||
}
|
||||
|
||||
async function runSlArgs(context: KtxCliCommandContext, args: KtxSlArgs): Promise<void> {
|
||||
const runner = context.deps.sl ?? (await import('../sl.js')).runKtxSl;
|
||||
context.setExitCode(await runner(args, context.io));
|
||||
|
|
@ -155,7 +145,7 @@ export function registerSlCommands(program: Command, context: KtxCliCommandConte
|
|||
format: options.format,
|
||||
execute: options.execute === true,
|
||||
cliVersion: context.packageInfo.version,
|
||||
runtimeInstallPolicy: runtimeInstallPolicy(options),
|
||||
runtimeInstallPolicy: runtimeInstallPolicyFromFlags(options),
|
||||
...(options.maxRows !== undefined ? { maxRows: options.maxRows } : {}),
|
||||
});
|
||||
await runSlArgs(context, args);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
|
|||
import {
|
||||
createManagedPythonSemanticLayerComputePort,
|
||||
managedRuntimeInstallCommand,
|
||||
runtimeInstallPolicyFromFlags,
|
||||
} from './managed-python-command.js';
|
||||
import type {
|
||||
InstalledKtxRuntimeManifest,
|
||||
|
|
@ -114,6 +115,21 @@ describe('managedRuntimeInstallCommand', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('runtimeInstallPolicyFromFlags', () => {
|
||||
it('maps command flags to managed runtime install policies', () => {
|
||||
expect(runtimeInstallPolicyFromFlags({})).toBe('prompt');
|
||||
expect(runtimeInstallPolicyFromFlags({ yes: false })).toBe('prompt');
|
||||
expect(runtimeInstallPolicyFromFlags({ yes: true })).toBe('auto');
|
||||
expect(runtimeInstallPolicyFromFlags({ input: false })).toBe('never');
|
||||
});
|
||||
|
||||
it('rejects conflicting runtime install flags', () => {
|
||||
expect(() => runtimeInstallPolicyFromFlags({ yes: true, input: false })).toThrow(
|
||||
'Choose only one runtime install mode: --yes or --no-input',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createManagedPythonSemanticLayerComputePort', () => {
|
||||
it('uses the managed ktx-daemon executable when the runtime is ready', async () => {
|
||||
const io = makeIo();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,19 @@ import {
|
|||
|
||||
export type KtxManagedPythonInstallPolicy = 'prompt' | 'auto' | 'never';
|
||||
|
||||
export function runtimeInstallPolicyFromFlags(options: {
|
||||
yes?: boolean;
|
||||
input?: boolean;
|
||||
}): KtxManagedPythonInstallPolicy {
|
||||
if (options.yes === true && options.input === false) {
|
||||
throw new Error('Choose only one runtime install mode: --yes or --no-input');
|
||||
}
|
||||
if (options.yes === true) {
|
||||
return 'auto';
|
||||
}
|
||||
return options.input === false ? 'never' : 'prompt';
|
||||
}
|
||||
|
||||
export interface ManagedPythonCommandRuntime {
|
||||
layout: ManagedPythonRuntimeLayout;
|
||||
manifest: InstalledKtxRuntimeManifest;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue