Skip to main content

agent_can/
internal_cli.rs

1use clap::{Parser, Subcommand};
2use std::ffi::{OsStr, OsString};
3
4#[derive(Debug, Parser)]
5#[command(name = "agent-can", hide = true)]
6struct InternalCli {
7    #[command(subcommand)]
8    command: InternalCommand,
9}
10
11#[derive(Debug, Subcommand)]
12pub enum InternalCommand {
13    BusDaemon {
14        #[arg(long)]
15        bus: String,
16        #[arg(long)]
17        config_path: String,
18    },
19}
20
21pub fn parse_from_env_if_internal() -> Option<InternalCommand> {
22    let raw_args = std::env::args_os().collect::<Vec<_>>();
23    if raw_args
24        .get(1)
25        .is_none_or(|arg| arg != OsStr::new("__internal"))
26    {
27        return None;
28    }
29
30    let args = std::iter::once(raw_args[0].clone())
31        .chain(raw_args.into_iter().skip(2))
32        .collect::<Vec<OsString>>();
33    Some(InternalCli::parse_from(args).command)
34}