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    SessionDaemon {
14        #[arg(long)]
15        config_path: String,
16    },
17}
18
19pub fn parse_from_env_if_internal() -> Option<InternalCommand> {
20    let raw_args = std::env::args_os().collect::<Vec<_>>();
21    if raw_args
22        .get(1)
23        .is_none_or(|arg| arg != OsStr::new("__internal"))
24    {
25        return None;
26    }
27
28    let args = std::iter::once(raw_args[0].clone())
29        .chain(raw_args.into_iter().skip(2))
30        .collect::<Vec<OsString>>();
31    Some(InternalCli::parse_from(args).command)
32}