mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-10 08:05:14 +02:00
61 lines
2.4 KiB
TypeScript
61 lines
2.4 KiB
TypeScript
import { resolve } from 'node:path';
|
|
import type { Command } from '@commander-js/extra-typings';
|
|
import { type CommandWithGlobalOptions, type KtxCliCommandContext, resolveCommandProjectDir } from './cli-program.js';
|
|
import { registerCompletionCommands } from './commands/completion-commands.js';
|
|
import { registerConnectionMappingCommands } from './commands/connection-commands.js';
|
|
import { registerIngestCommands } from './commands/ingest-commands.js';
|
|
import { registerRuntimeCommands } from './commands/runtime-commands.js';
|
|
import { registerScanCommands } from './commands/scan-commands.js';
|
|
import { profileMark } from './startup-profile.js';
|
|
|
|
profileMark('module:dev');
|
|
|
|
export function registerDevCommands(program: Command, context: KtxCliCommandContext): void {
|
|
const dev = program
|
|
.command('dev', { hidden: true })
|
|
.description('Low-level diagnostics, scans, adapter commands, and mapping tools')
|
|
.showHelpAfterError();
|
|
|
|
dev.hook('preAction', (_thisCommand, actionCommand) => {
|
|
context.writeDebug?.('dev', actionCommand);
|
|
});
|
|
|
|
dev.action(() => {
|
|
dev.outputHelp();
|
|
context.setExitCode(0);
|
|
});
|
|
|
|
dev
|
|
.command('init')
|
|
.description('Initialize a Git-backed KTX project directory for maintenance scripts')
|
|
.argument('[directory]', 'Project directory')
|
|
.option('--name <name>', 'Project name written to ktx.yaml')
|
|
.option('--force', 'Rewrite ktx.yaml and scaffold files in an existing project', false)
|
|
.action(
|
|
async (
|
|
projectDir: string | undefined,
|
|
commandOptions: { name?: string; force?: boolean },
|
|
command: CommandWithGlobalOptions,
|
|
) => {
|
|
context.setExitCode(
|
|
await context.runInit(
|
|
{
|
|
projectDir: projectDir ? resolve(projectDir) : resolveCommandProjectDir(command),
|
|
...(commandOptions.name ? { projectName: commandOptions.name } : {}),
|
|
force: commandOptions.force === true,
|
|
},
|
|
context.io,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
|
|
registerRuntimeCommands(dev, context);
|
|
registerScanCommands(dev, context);
|
|
registerIngestCommands(dev, context, {
|
|
runIngestWithProgress: async (ingestArgs, ingestIo, ingestDeps, defaultRunIngest) =>
|
|
await (ingestDeps.ingest ?? defaultRunIngest)(ingestArgs, ingestIo),
|
|
});
|
|
registerConnectionMappingCommands(dev, context);
|
|
registerCompletionCommands(dev, context, program);
|
|
}
|