2.0 KiB
bin — suaveplan-audio entry point
(no submodules)
Purpose
This module is the bin shebang entry for the suaveplan-audio command. It
is the only file in the package with side effects: when executed as a script
it installs a SIGINT handler, constructs an AudioCLI, dispatches
process.argv, and calls process.exit with the returned exit code. The
function main is also exported so tests and programmatic callers can drive
the exact dispatch path without spawning a subprocess.
The root barrel deliberately does NOT re-export this module — importing
@suaveplan/audio-cli should never read process.argv or attach signal
listeners.
Features
#!/usr/bin/env bunshebang so the installedbinruns through Bun.- Single
AbortControllerper invocation, threaded into every long-running command viacli.dispatch. - Two-tick
SIGINThandling: first signal aborts cooperatively, second signal callsprocess.exit(130)for force-exit. import.meta.urlself-test guard so importing the file as a module is a pure type/export operation.
Usage: Basic
$ suaveplan-audio --version
0.1.0
$ suaveplan-audio convert input.wav output.flac
Usage: Advanced
import { main } from "@suaveplan/audio-cli/bin";
const exitCode = await main(["analyze", "track.wav", "--lufs"]);
console.log("exit:", exitCode);
API Reference
main(argv: readonly string[]): Promise<number>— dispatch and return exit code without callingprocess.exit(caller's responsibility).
Implementation Notes
The import.meta.url === \file://${process.argv[1]}`check is the canonical Node ESM way to ask "am I running as the entry script?" It avoids the historicalrequire.main === moduleCJS idiom and keeps the file safe to import from tests. The singleAbortController` is threaded via the
dispatch's per-command argument extraction so the same signal reaches the
engine adapters as the spec mandates.