refactor(cli): extract common command options into reusable helpers

This commit is contained in:
Mohamed Boudra
2026-03-11 21:08:08 +07:00
parent b60d253926
commit e2cb67462d
9 changed files with 323 additions and 312 deletions
+18 -23
View File
@@ -1,29 +1,24 @@
import { Command } from "commander";
import { withOutput } from "../../output/index.js";
import { runSpeechModelsCommand } from "./models.js";
import { runSpeechDownloadCommand } from "./download.js";
function collectMultiple(value: string, previous: string[]): string[] {
return previous.concat([value]);
}
import { Command } from 'commander'
import { withOutput } from '../../output/index.js'
import { runSpeechModelsCommand } from './models.js'
import { runSpeechDownloadCommand } from './download.js'
import { addJsonAndDaemonHostOptions, collectMultiple } from '../../utils/command-options.js'
export function createSpeechCommand(): Command {
const speech = new Command("speech").description("Manage local speech models");
const speech = new Command('speech').description('Manage local speech models')
speech
.command("models")
.description("List local speech model download status")
.option("--json", "Output in JSON format")
.option("--host <host>", "Daemon host target (default: local socket/pipe, then localhost:6767)")
.action(withOutput(runSpeechModelsCommand));
addJsonAndDaemonHostOptions(
speech
.command('models')
.description('List local speech model download status')
).action(withOutput(runSpeechModelsCommand))
speech
.command("download")
.description("Download local speech models")
.option("--model <id>", "Model ID to download (repeatable)", collectMultiple, [])
.option("--json", "Output in JSON format")
.option("--host <host>", "Daemon host target (default: local socket/pipe, then localhost:6767)")
.action(withOutput(runSpeechDownloadCommand));
addJsonAndDaemonHostOptions(
speech
.command('download')
.description('Download local speech models')
.option('--model <id>', 'Model ID to download (repeatable)', collectMultiple, [])
).action(withOutput(runSpeechDownloadCommand))
return speech;
return speech
}