ev3_runner/
cli.rs

1pub use clap::Parser;
2use std::path::PathBuf;
3
4#[derive(Debug, clap::Parser)]
5#[command(
6    name = "ev3-runner",
7    version,
8    about = "Upload and run binaries on LEGO EV3 robots",
9    long_about = "A tool to upload and execute programs on LEGO EV3 robots running ev3dev.\n\
10                  Uses hash-based deduplication to skip uploads when files haven't changed.\n\
11                  Supports password protection and real-time output streaming."
12)]
13pub struct Cli {
14    #[clap(
15        short,
16        long,
17        global = true,
18        action = clap::ArgAction::Count,
19        help = "Increase logging verbosity (-v: INFO, -vv: DEBUG, -vvv: TRACE)"
20    )]
21    pub verbose: u8,
22    #[command(subcommand)]
23    pub command: Commands,
24}
25
26#[derive(Debug, clap::Subcommand)]
27pub enum Commands {
28    /// Run as server (typically on the EV3)
29    #[command(
30        long_about = "Start the server to accept file uploads and execute programs.\n\
31                            This mode should be run on the EV3 robot."
32    )]
33    Server(Server),
34    /// Run as client (on your development machine)
35    #[command(
36        long_about = "Connect to a server to upload files or execute programs.\n\
37                            This mode should be run on your development machine."
38    )]
39    Client(Client),
40}
41
42#[derive(Debug, clap::Args)]
43pub struct Client {
44    #[command(subcommand)]
45    pub action: Action,
46}
47
48#[derive(Debug, clap::Subcommand)]
49pub enum Action {
50    /// Upload a file to the server
51    #[command(long_about = "Upload a file to the server without executing it.\n\
52                            The file will be made executable on the server.")]
53    Upload(ClientArgs),
54    /// Upload and run a file on the server
55    #[command(
56        long_about = "Upload a file to the server and execute it immediately.\n\
57                            Output from the program will be streamed back in real-time.\n\
58                            If the file hash matches what's already on the server, upload is skipped."
59    )]
60    Run(ClientArgs),
61}
62
63#[derive(Debug, clap::Args)]
64pub struct ClientArgs {
65    /// Path to the local file to upload
66    #[arg(value_name = "FILE")]
67    pub filepath: PathBuf,
68
69    /// Where to save the file on the server
70    #[clap(
71        short,
72        long,
73        value_name = "PATH",
74        help = "Remote file path (default: same filename as local)"
75    )]
76    pub remote_path: Option<PathBuf>,
77
78    /// Server address and port
79    #[clap(
80        default_value = "127.0.0.1:6767",
81        value_name = "HOST:PORT",
82        help = "Server address in format IP:PORT"
83    )]
84    pub host: String,
85
86    /// Password for authentication
87    #[clap(
88        short,
89        long,
90        default_value = "maker",
91        value_name = "PASSWORD",
92        help = "Password to authenticate with the server"
93    )]
94    pub password: String,
95}
96
97#[derive(Debug, clap::Args)]
98pub struct Server {
99    /// Port to listen on
100    #[clap(
101        short = 'p',
102        long,
103        default_value = "6767",
104        value_name = "PORT",
105        help = "TCP port for incoming connections"
106    )]
107    pub server_port: u16,
108
109    /// Server password
110    #[clap(
111        short,
112        long,
113        default_value = "maker",
114        value_name = "PASSWORD",
115        help = "Password required for client authentication"
116    )]
117    pub password: String,
118}