bin.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env node
  2. /**
  3. * Process wrapper for `dsh-cli-demo`; covered parsing and task execution live in
  4. * `cli.ts` while this entry owns Unix signal-to-exit-code mapping.
  5. * @module @deepseek-ai/dsh-cli-demo/bin
  6. */
  7. import { installFailLoud } from '@deepseek-ai/dsh-app-boot'
  8. import { executeCli } from './cli.ts'
  9. const NAME = 'dsh-cli-demo'
  10. /* v8 ignore start -- thin self-executing process glue; built-bin tests exercise
  11. real argv, signals, Loader boot, output, and exit codes */
  12. const abort = new AbortController()
  13. let signalExitCode: number | undefined
  14. const interrupt = (signal: 'SIGINT' | 'SIGTERM', code: number): void => {
  15. signalExitCode ??= code
  16. if (!abort.signal.aborted) abort.abort(`received ${signal}`)
  17. }
  18. const onSigint = (): void => { interrupt('SIGINT', 130) }
  19. const onSigterm = (): void => { interrupt('SIGTERM', 143) }
  20. const uninstallFailLoud = installFailLoud(NAME)
  21. process.on('SIGINT', onSigint)
  22. process.on('SIGTERM', onSigterm)
  23. try {
  24. const code = await executeCli(process.argv.slice(2), { signal: abort.signal })
  25. process.exitCode = signalExitCode ?? code
  26. } finally {
  27. process.off('SIGINT', onSigint)
  28. process.off('SIGTERM', onSigterm)
  29. uninstallFailLoud()
  30. }
  31. /* v8 ignore stop */