loopd, bxctl, inferproxy: read args_os instead of panicking

M3a review finding 7, for the other three roles. loopd keeps its config path
as a path; bxctl and inferproxy take text arguments and answer one that is
not UTF-8 with their usage.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-22 21:07:59 -07:00
co-authored by Claude Opus 5.5
parent 6af89f7c60
commit 33994d0dc6
6 changed files with 97 additions and 11 deletions
+10 -9
View File
@@ -16,11 +16,12 @@ use loopd::selftest::{SelfTestError, run};
use loopd::tools::{Registry, ToolPort};
fn main() -> ExitCode {
let args: Vec<String> = std::env::args().skip(1).collect();
let args: Vec<&str> = args.iter().map(String::as_str).collect();
match args.as_slice() {
["selftest", "--config", path] => run_selftest(path),
["serve", "--config", path] => run_serve(path),
// `args_os`: the config path need not be UTF-8, and `args` would panic on one that is not.
let args: Vec<std::ffi::OsString> = std::env::args_os().skip(1).collect();
let words: Vec<Option<&str>> = args.iter().map(|a| a.to_str()).collect();
match (words.as_slice(), args.get(2)) {
([Some("selftest"), Some("--config"), _], Some(path)) => run_selftest(Path::new(path)),
([Some("serve"), Some("--config"), _], Some(path)) => run_serve(Path::new(path)),
_ => {
eprintln!("usage: loopd selftest --config <path>");
eprintln!("usage: loopd serve --config <path>");
@@ -46,8 +47,8 @@ fn run_selftest_check(client: &Client) -> Result<(), SelfTestError> {
}
}
fn run_selftest(path: &str) -> ExitCode {
let cfg = match Config::load(Path::new(path)) {
fn run_selftest(path: &Path) -> ExitCode {
let cfg = match Config::load(path) {
Ok(cfg) => cfg,
Err(e) => {
eprintln!("loopd: {e}");
@@ -62,8 +63,8 @@ fn run_selftest(path: &str) -> ExitCode {
}
}
fn run_serve(path: &str) -> ExitCode {
let cfg = match Config::load(Path::new(path)) {
fn run_serve(path: &Path) -> ExitCode {
let cfg = match Config::load(path) {
Ok(cfg) => cfg,
Err(e) => {
eprintln!("loopd: {e}");