Added longopts to tuxrecord2.

This commit is contained in:
Johannes Findeisen 2026-10-15 03:34:39 +02:00
commit e585472da0
2 changed files with 25 additions and 20 deletions

View file

@ -34,15 +34,19 @@ tuxrecord2
# Record for N seconds
tuxrecord2 -d 30
tuxrecord2 --duration 30
# Specify output directory
tuxrecord2 -o /path/to/dir
tuxrecord2 --output /path/to/dir
# Use a custom filename prefix
tuxrecord2 -p myrec
tuxrecord2 --prefix myrec
# Use a specific ALSA capture device
tuxrecord2 -D hw:1,0
tuxrecord2 --device hw:1,0
# Encode to FLAC (lossless) or MP3 (lossy) in real time
tuxrecord2 -f flac
@ -54,14 +58,14 @@ tuxrecord2 -D pipewire
## Options
| Option | Description |
| -------------- | -------------------------------------------------------- |
| `-o <dir>` | Output directory (default: current directory) |
| `-d <secs>` | Stop automatically after `<secs>` seconds |
| `-p <prefix>` | Filename prefix instead of `tuxrecord2` |
| `-D <device>` | ALSA capture device (default: `default`; `pipewire` on PipeWire systems) |
| `-f, --format <fmt>` | Output format: `wav`, `flac` or `mp3` (default: `wav`) |
| `-h, --help` | Show help |
| Option | Description |
| ----------------------- | -------------------------------------------------------- |
| `-o, --output <dir>` | Output directory (default: current directory) |
| `-d, --duration <secs>` | Stop automatically after `<secs>` seconds |
| `-p, --prefix <prefix>` | Filename prefix instead of `tuxrecord2` |
| `-D, --device <device>` | ALSA capture device (default: `default`; `pipewire` on PipeWire systems) |
| `-f, --format <fmt>` | Output format: `wav`, `flac` or `mp3` (default: `wav`) |
| `-h, --help` | Show help |
Run `arecord -l` to list available ALSA capture devices. On systems with
PipeWire, list the PipeWire source nodes with `pactl list short sources`

View file

@ -84,12 +84,12 @@ fn usage() {
\x20 tuxrecord2 [options]\n\
\n\
OPTIONS\n\
\x20 -o <dir> Output directory (default: current directory)\n\
\x20 -d <secs> Stop automatically after <secs> seconds (default: until q or Ctrl+C)\n\
\x20 -p <prefix> Filename prefix instead of \"{prefix}\" (default: {prefix})\n\
\x20 -D <device> ALSA capture device (default: \"{device}\")\n\
\x20 -f, --format F Output format: {formats} (default: {format})\n\
\x20 -h, --help Show this help\n\
\x20 -o, --output <dir> Output directory (default: current directory)\n\
\x20 -d, --duration <secs> Stop automatically after <secs> seconds (default: until q or Ctrl+C)\n\
\x20 -p, --prefix <prefix> Filename prefix instead of \"{prefix}\" (default: {prefix})\n\
\x20 -D, --device <device> ALSA capture device (default: \"{device}\")\n\
\x20 -f, --format <fmt> Output format: {formats} (default: {format})\n\
\x20 -h, --help Show this help\n\
\n\
The file is written as <prefix>__<timestamp>.<ext> where <ext> is wav, flac, or mp3.\n\
\n\
@ -425,8 +425,9 @@ fn timestamp() -> String {
/*
* Program entry point: parse options, record audio, encode the output.
*
* Parses the command line (-o dir, -d seconds, -p prefix, -D device,
* -f/--format, -h/--help), validates the output directory, builds the
* Parses the command line (-o/--output dir, -d/--duration seconds,
* -p/--prefix prefix, -D/--device device, -f/--format, -h/--help),
* validates the output directory, builds the
* output filename "<dir>/<prefix>__<timestamp>.<ext>" and opens the ALSA
* capture device and the output encoder. It then installs SIGINT/SIGTERM
* handlers and runs a poll() loop that reads captured PCM frames from ALSA
@ -449,7 +450,7 @@ fn run() -> i32 {
let mut i = 1;
while i < args.len() {
match args[i].as_str() {
"-o" => {
"-o" | "--output" => {
i += 1;
if i >= args.len() {
usage();
@ -457,7 +458,7 @@ fn run() -> i32 {
}
output_dir = args[i].clone();
}
"-d" => {
"-d" | "--duration" => {
i += 1;
if i >= args.len() {
usage();
@ -471,7 +472,7 @@ fn run() -> i32 {
}
}
}
"-p" => {
"-p" | "--prefix" => {
i += 1;
if i >= args.len() || args[i].is_empty() {
usage();
@ -479,7 +480,7 @@ fn run() -> i32 {
}
prefix = args[i].clone();
}
"-D" => {
"-D" | "--device" => {
i += 1;
if i >= args.len() || args[i].is_empty() {
usage();