feat(M7.1): define the typed command line

Add planned server, TUI, validation, device, status, and profile commands with typed session-only audio overrides. Keep inactive commands explicit until their server increments land.

Tests: cargo test -p fader_master --all-targets --all-features

Tests: cargo clippy -p fader_master --all-targets --all-features --locked -- -D warnings
This commit is contained in:
Dandaedre 2026-10-15 00:10:19 +02:00
parent d5229e5eca
commit e1fe9b2733
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
7 changed files with 270 additions and 2 deletions

122
Cargo.lock generated
View File

@ -49,6 +49,62 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "anstream"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
[[package]]
name = "anstyle-parse"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys 0.61.2",
]
[[package]]
name = "anyhow"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
[[package]]
name = "autocfg"
version = "1.5.1"
@ -137,6 +193,52 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
[[package]]
name = "clap"
version = "4.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 3.0.6",
]
[[package]]
name = "clap_lex"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486"
[[package]]
name = "colorchoice"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
[[package]]
name = "combine"
version = "4.6.8"
@ -322,6 +424,8 @@ dependencies = [
name = "fader_master"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"fader-config",
"fader-core",
"midi",
@ -484,6 +588,12 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]]
name = "itertools"
version = "0.13.0"
@ -781,6 +891,12 @@ version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "parking_lot"
version = "0.12.5"
@ -1386,6 +1502,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "volume_lib"
version = "0.1.0"

View File

@ -12,6 +12,8 @@ publish = false
[workspace.dependencies]
alsa = "0.12.1"
anyhow = "1.0.104"
clap = { version = "4.6.7", features = ["derive"] }
fader-config = { path = "config" }
fader-core = { path = "core" }
midi = { path = "midi" }

View File

@ -8,6 +8,8 @@ repository.workspace = true
publish.workspace = true
[dependencies]
anyhow.workspace = true
clap.workspace = true
fader-config.workspace = true
fader-core.workspace = true
midi.workspace = true

73
fader_master/src/cli.rs Normal file
View File

@ -0,0 +1,73 @@
use std::path::PathBuf;
use clap::{Parser, Subcommand, ValueEnum};
use volume_lib::{AdapterChoice, AudioBackend};
/// fader_master server, diagnostics, and terminal client.
#[derive(Clone, Debug, Parser, PartialEq)]
#[command(version, about)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Clone, Debug, PartialEq, Subcommand)]
pub enum Command {
/// Run the persistent audio/MIDI server.
Serve {
/// Validated profile to activate.
#[arg(long)]
config: PathBuf,
/// Session-only audio backend override.
#[arg(long, value_enum)]
audio: Option<AudioArgument>,
},
/// Open the terminal mixer connected to the running server.
Tui {
/// Override the XDG runtime socket path.
#[arg(long)]
socket: Option<PathBuf>,
},
/// Validate a profile without opening devices or changing audio.
Validate {
#[arg(long)]
config: PathBuf,
},
/// List MIDI ports and durable identity metadata.
Devices,
/// Print a snapshot from the running server.
Status {
/// Override the XDG runtime socket path.
#[arg(long)]
socket: Option<PathBuf>,
},
/// Manage the active profile.
Profile {
#[command(subcommand)]
command: ProfileCommand,
},
}
#[derive(Clone, Debug, PartialEq, Subcommand)]
pub enum ProfileCommand {
/// Request activation of a validated profile ID.
Switch { id: String },
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub enum AudioArgument {
Auto,
Pulse,
Pipewire,
}
impl AudioArgument {
#[must_use]
pub const fn choice(self) -> AdapterChoice {
match self {
Self::Auto => AdapterChoice::Auto,
Self::Pulse => AdapterChoice::Manual(AudioBackend::Pulse),
Self::Pipewire => AdapterChoice::Manual(AudioBackend::PipeWire),
}
}
}

View File

@ -2,6 +2,8 @@
#![forbid(unsafe_code)]
pub mod cli;
use std::{collections::BTreeMap, error::Error, fmt};
use fader_core::{

View File

@ -1,3 +1,21 @@
fn main() -> std::io::Result<()> {
tui::run()
use std::fs;
use anyhow::{Context, Result, bail};
use clap::Parser;
use fader_config::Profile;
use fader_master::cli::{Cli, Command};
fn main() -> Result<()> {
match Cli::parse().command {
Command::Tui { socket: None } => tui::run().context("terminal UI failed"),
Command::Validate { config } => {
let input = fs::read_to_string(&config)
.with_context(|| format!("could not read profile {}", config.display()))?;
let profile = Profile::parse(&input)
.with_context(|| format!("profile {} is invalid", config.display()))?;
println!("profile {:?} is valid", profile.id().as_str());
Ok(())
}
command => bail!("{command:?} is not available until the local server increment is active"),
}
}

49
fader_master/tests/cli.rs Normal file
View File

@ -0,0 +1,49 @@
use std::path::PathBuf;
use clap::{CommandFactory, Parser};
use fader_master::cli::{AudioArgument, Cli, Command};
#[test]
fn every_planned_command_is_present_in_help() {
let help = Cli::command().render_long_help().to_string();
for command in ["serve", "tui", "validate", "devices", "status", "profile"] {
assert!(help.contains(command), "missing {command:?} in help");
}
}
#[test]
fn serve_requires_a_config_and_parses_session_override() {
assert!(Cli::try_parse_from(["fader_master", "serve"]).is_err());
assert_eq!(
Cli::try_parse_from([
"fader_master",
"serve",
"--config",
"profile.toml",
"--audio",
"pulse",
])
.unwrap()
.command,
Command::Serve {
config: PathBuf::from("profile.toml"),
audio: Some(AudioArgument::Pulse),
}
);
}
#[test]
fn unknown_commands_and_adapter_values_are_rejected() {
assert!(Cli::try_parse_from(["fader_master", "unknown"]).is_err());
assert!(
Cli::try_parse_from([
"fader_master",
"serve",
"--config",
"profile.toml",
"--audio",
"alsa-master",
])
.is_err()
);
}