FDS/OS 1.0
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
mod burning;
|
||||
mod consumers;
|
||||
mod data_sessions;
|
||||
mod media;
|
||||
mod power;
|
||||
mod profiles;
|
||||
mod recovery;
|
||||
mod server;
|
||||
mod software;
|
||||
use clap::Parser;
|
||||
use fds_common::{Error, Result, topology};
|
||||
use std::{path::PathBuf, process::ExitCode};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(
|
||||
version,
|
||||
about = "Run the root cartridge service or inspect USB topology"
|
||||
)]
|
||||
struct Cli {
|
||||
/// Notify s6 when the service is ready.
|
||||
#[arg(long, conflicts_with = "topology")]
|
||||
notify: bool,
|
||||
/// Inspect topology without starting the service or mounting devices.
|
||||
#[arg(long, value_name = "SYSFS_ROOT")]
|
||||
topology: Option<PathBuf>,
|
||||
}
|
||||
fn run() -> Result<()> {
|
||||
let cli = Cli::parse();
|
||||
if let Some(sys) = cli.topology {
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&topology::devices(&sys)?)
|
||||
.map_err(|e| Error(e.to_string()))?
|
||||
);
|
||||
Ok(())
|
||||
} else {
|
||||
server::run(cli.notify)
|
||||
}
|
||||
}
|
||||
fn main() -> ExitCode {
|
||||
match run() {
|
||||
Ok(()) => ExitCode::SUCCESS,
|
||||
Err(e) => {
|
||||
eprintln!("fds-cartridged: {e}");
|
||||
ExitCode::FAILURE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod cli_tests {
|
||||
use super::*;
|
||||
use clap::{CommandFactory, Parser};
|
||||
#[test]
|
||||
fn typed_command_contract() {
|
||||
Cli::command().debug_assert();
|
||||
assert!(!Cli::try_parse_from(["fds-cartridged"]).unwrap().notify);
|
||||
assert!(
|
||||
Cli::try_parse_from(["fds-cartridged", "--notify"])
|
||||
.unwrap()
|
||||
.notify
|
||||
);
|
||||
assert!(Cli::try_parse_from(["fds-cartridged", "--topology", "/sys"]).is_ok());
|
||||
assert!(Cli::try_parse_from(["fds-cartridged", "--notify", "--topology", "/sys"]).is_err());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user