twinleaf_tools/cli/
rpc.rs1use clap::{
2 builder::{PossibleValuesParser, TypedValueParser, ValueHint},
3 Args, Subcommand,
4};
5use twinleaf::device::{util, RpcValueType};
6
7use crate::TioOpts;
8
9#[derive(Args, Debug)]
10#[command(args_conflicts_with_subcommands = true, arg_required_else_help = true)]
11pub struct RpcCli {
12 #[command(flatten)]
13 pub tio: TioOpts,
14
15 #[command(subcommand)]
16 pub subcommands: Option<RPCSubcommands>,
17
18 #[arg(value_hint = ValueHint::Other)]
20 pub rpc_name: Option<String>,
21
22 #[arg(
24 allow_negative_numbers = true,
25 value_name = "ARG",
26 value_hint = ValueHint::Other,
27 help_heading = "RPC Arguments"
28 )]
29 pub rpc_arg: Option<String>,
30
31 #[arg(
33 short = 't',
34 long = "req-type",
35 value_parser = PossibleValuesParser::new(util::RPC_TYPE_NAMES)
36 .map(|s: String| util::parse_rpc_type(&s).expect("validated by possible-values")),
37 help_heading = "Type Options",
38 )]
39 pub req_type: Option<RpcValueType>,
40
41 #[arg(
43 short = 'T',
44 long = "rep-type",
45 value_parser = PossibleValuesParser::new(util::RPC_TYPE_NAMES)
46 .map(|s: String| util::parse_rpc_type(&s).expect("validated by possible-values")),
47 help_heading = "Type Options",
48 )]
49 pub rep_type: Option<RpcValueType>,
50
51 #[arg(short = 'd', long)]
53 pub debug: bool,
54}
55
56#[derive(Subcommand, Debug)]
57pub enum RPCSubcommands {
58 List {
60 #[command(flatten)]
61 tio: TioOpts,
62 },
63 Dump {
65 #[command(flatten)]
66 tio: TioOpts,
67
68 #[arg(value_hint = ValueHint::Other)]
70 rpc_name: String,
71
72 #[arg(long)]
74 capture: bool,
75 },
76}