1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
// SPDX-FileCopyrightText: 2026 Blackcat InformaticsĀ® Inc. <paudley@blackcatinformatics.ca> // SPDX-License-Identifier: MIT OR Apache-2.0 OR MulanPSL-2.0 //! Dispatch and report string-producing measurement examples. use std::process::ExitCode; pub(crate) fn run( name: &str, sample: fn() -> Result<String, String>, explicit: fn(&[String]) -> Result<String, String>, ) -> ExitCode { let args: Vec<String> = std::env::args().skip(1).collect(); let outcome = if args.is_empty() { sample() } else { explicit(&args) }; match outcome { Ok(summary) => { println!("{summary}"); ExitCode::SUCCESS } Err(error) => { eprintln!("{name}: {error}"); ExitCode::FAILURE } } }