Skip to main content

agent_can/cli/
args.rs

1use clap::{Args, Parser, Subcommand};
2
3#[derive(Debug, Parser)]
4#[command(
5    name = "agent-can",
6    version,
7    about = "Stateful CAN control runtime CLI"
8)]
9pub struct CliArgs {
10    #[arg(long, global = true, env = "AGENT_CAN_JSON", default_value_t = false)]
11    pub json: bool,
12
13    #[arg(long, global = true, env = "AGENT_CAN_BUS", default_value = "default")]
14    pub bus: String,
15
16    #[command(subcommand)]
17    pub command: Option<Command>,
18}
19
20#[derive(Debug, Subcommand)]
21pub enum Command {
22    Open(OpenArgs),
23    Status,
24    Mailboxes,
25    Mailbox(MailboxArgs),
26    SendRaw(SendRawArgs),
27    SendMessage(SendMessageArgs),
28    Bus(BusArgs),
29    Close,
30}
31
32#[derive(Debug, Args)]
33pub struct OpenArgs {
34    #[arg(long)]
35    pub adapter: String,
36    #[arg(long)]
37    pub dbc: String,
38    #[arg(long)]
39    pub bitrate: u32,
40    #[arg(long, default_value_t = 0)]
41    pub bitrate_data: u32,
42    #[arg(long, default_value_t = false)]
43    pub fd: bool,
44}
45
46#[derive(Debug, Args)]
47pub struct MailboxArgs {
48    pub message: String,
49}
50
51#[derive(Debug, Args)]
52pub struct SendRawArgs {
53    pub arb_id: String,
54    pub data_hex: String,
55    #[arg(long)]
56    pub flags: Option<u8>,
57}
58
59#[derive(Debug, Args)]
60pub struct SendMessageArgs {
61    pub message: String,
62    #[arg(required = true)]
63    pub signals: Vec<String>,
64}
65
66#[derive(Debug, Args)]
67pub struct BusArgs {
68    #[command(subcommand)]
69    pub command: BusCommand,
70}
71
72#[derive(Debug, Subcommand)]
73pub enum BusCommand {
74    List,
75}