ktx/packages/cli/src/commands/status-commands.ts

77 lines
2.8 KiB
TypeScript
Raw Normal View History

2026-05-10 23:12:26 +02:00
import type { Command } from '@commander-js/extra-typings';
2026-05-10 23:51:24 +02:00
import type { KtxCliCommandContext } from '../cli-program.js';
2026-05-12 23:51:46 +02:00
import { resolveCommandProjectDir, resolveCommandProjectDirOverride } from '../cli-program.js';
import { findNearestKtxProjectDir } from '../project-resolver.js';
function outputMode(options: { json?: boolean }): 'plain' | 'json' {
return options.json === true ? 'json' : 'plain';
}
function inputMode(options: { input?: boolean }): { inputMode?: 'disabled' } {
return options.input === false ? { inputMode: 'disabled' } : {};
}
2026-05-10 23:12:26 +02:00
2026-05-10 23:51:24 +02:00
export function registerStatusCommands(program: Command, context: KtxCliCommandContext): void {
2026-05-10 23:12:26 +02:00
program
.command('status')
2026-05-12 23:51:46 +02:00
.description('Check current KTX setup and project readiness')
2026-05-10 23:12:26 +02:00
.option('--json', 'Print JSON output', false)
.option('-v, --verbose', 'Show every check, including passing ones', false)
.option('--validate', 'Only validate the ktx.yaml schema; skip readiness checks', false)
.option('--fast', 'Skip checks that require external communication (DB probes, auth probes)', false)
2026-05-12 23:51:46 +02:00
.option('--no-input', 'Disable interactive terminal input')
.action(
async (
options: { json?: boolean; verbose?: boolean; validate?: boolean; fast?: boolean; input?: boolean },
command,
) => {
const runner = context.deps.doctor ?? (await import('../doctor.js')).runKtxDoctor;
const explicitOrEnvProjectDir = resolveCommandProjectDirOverride(command);
const nearestProjectDir = explicitOrEnvProjectDir ? undefined : findNearestKtxProjectDir(process.cwd());
if (options.validate === true) {
context.setExitCode(
await runner(
{
command: 'validate',
projectDir: resolveCommandProjectDir(command),
outputMode: outputMode(options),
...inputMode(options),
},
context.io,
),
);
return;
}
if (!explicitOrEnvProjectDir && !nearestProjectDir) {
context.setExitCode(
await runner(
{
command: 'setup',
outputMode: outputMode(options),
verbose: options.verbose === true,
...inputMode(options),
},
context.io,
),
);
return;
}
2026-05-12 23:51:46 +02:00
context.setExitCode(
await runner(
{
command: 'project',
projectDir: resolveCommandProjectDir(command),
2026-05-12 23:51:46 +02:00
outputMode: outputMode(options),
verbose: options.verbose === true,
fast: options.fast === true,
2026-05-12 23:51:46 +02:00
...inputMode(options),
},
context.io,
),
);
},
);
2026-05-10 23:12:26 +02:00
}