Skip to main content

twinleaf_tools/cli/
mod.rs

1mod capture;
2mod dump;
3mod health;
4mod log;
5mod monitor;
6mod proxy;
7mod rpc;
8mod simulate;
9mod upgrade;
10
11pub use capture::CaptureCli;
12pub use dump::DumpCli;
13pub use health::HealthCli;
14pub use log::{
15    parse_csv_target, CsvTarget, LogCli, LogSubcommands, MetaSubcommands, SplitLevel, SplitPolicy,
16    StreamSel,
17};
18pub use monitor::MonitorCli;
19pub use proxy::{MountArg, ProxyCli, ProxySubcommands};
20pub use rpc::{RPCSubcommands, RpcCli};
21pub use simulate::SimulateCli;
22pub use upgrade::UpgradeCli;
23
24use clap::{Parser, Subcommand};
25use clap_complete::Shell;
26
27pub(crate) fn nonneg_f64(s: &str) -> Result<f64, String> {
28    let v: f64 = s
29        .parse()
30        .map_err(|e: std::num::ParseFloatError| e.to_string())?;
31    if v < 0.0 {
32        Err("must be >= 0".into())
33    } else {
34        Ok(v)
35    }
36}
37
38#[derive(Parser, Debug)]
39#[command(
40    name = "tio",
41    version,
42    about = "Twinleaf sensor management and data logging tool",
43    disable_help_subcommand = true
44)]
45pub struct TioCli {
46    #[command(subcommand)]
47    pub command: Commands,
48}
49
50#[derive(Subcommand, Debug)]
51pub enum Commands {
52    /// List connected devices
53    List {
54        /// Include serial ports with unknown VID/PID
55        #[arg(short = 'a', long = "all")]
56        all: bool,
57    },
58
59    /// Live sensor data display
60    Monitor(MonitorCli),
61
62    /// Live timing and rate diagnostics
63    Health(HealthCli),
64
65    /// Dump raw packets from a device
66    Dump(DumpCli),
67
68    /// Log samples to a file
69    Log(LogCli),
70
71    /// Execute a device RPC
72    Rpc(RpcCli),
73
74    /// Trigger and read a capture RPC
75    Capture(CaptureCli),
76
77    /// Upgrade device firmware
78    #[command(alias = "firmware-upgrade")]
79    Upgrade(UpgradeCli),
80
81    /// Multiplex a sensor over TCP
82    Proxy(ProxyCli),
83
84    /// Run a simulated sine wave Twinleaf device over UDP
85    Simulate(SimulateCli),
86
87    /// (deprecated, use `simulate`) Run a simulated sine wave Twinleaf device over UDP
88    #[command(hide = true)]
89    Test(SimulateCli),
90
91    /// Generate shell completions for tio
92    #[command(long_about = "\
93Generate shell completions for tio.
94
95Add one of these lines to your shell's config file:
96
97  Bash (~/.bashrc):
98    eval \"$(tio completions bash)\"
99
100  Zsh (~/.zshrc):
101    eval \"$(tio completions zsh)\"
102
103  Fish (~/.config/fish/config.fish):
104    tio completions fish | source
105
106  PowerShell ($PROFILE):
107    tio completions powershell | Invoke-Expression")]
108    Completions {
109        #[arg(value_enum)]
110        shell: Shell,
111    },
112}