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
+23
View File
@@ -0,0 +1,23 @@
import type { Command } from 'commander'
const JSON_OPTION_DESCRIPTION = 'Output in JSON format'
const DAEMON_HOST_OPTION_DESCRIPTION =
'Daemon host target (default: local socket/pipe, then localhost:6767)'
export function collectMultiple(value: string, previous: string[]): string[] {
return previous.concat([value])
}
export function addJsonOption<T extends Command>(command: T): T {
command.option('--json', JSON_OPTION_DESCRIPTION)
return command
}
export function addDaemonHostOption<T extends Command>(command: T): T {
command.option('--host <host>', DAEMON_HOST_OPTION_DESCRIPTION)
return command
}
export function addJsonAndDaemonHostOptions<T extends Command>(command: T): T {
return addDaemonHostOption(addJsonOption(command))
}