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 #[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 #[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 #[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 #[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 #[arg(value_name = "FILE")]
67 pub filepath: PathBuf,
68
69 #[clap(
71 short,
72 long,
73 default_value = "127.0.0.1:6767",
74 value_name = "HOST:PORT",
75 help = "Server address in format IP:PORT"
76 )]
77 pub host: String,
78
79 #[clap(
81 short,
82 long,
83 value_name = "PATH",
84 help = "Remote file path (default: same filename as local)"
85 )]
86 pub remote_path: Option<PathBuf>,
87
88 #[clap(
90 short,
91 long,
92 default_value = "maker",
93 value_name = "PASSWORD",
94 help = "Password to authenticate with the server"
95 )]
96 pub password: String,
97
98 #[clap(short, long, action = clap::ArgAction::SetFalse, help = "If the program should be started using brickrun")]
100 pub brickrun: bool,
101}
102
103#[derive(Debug, clap::Args)]
104pub struct Server {
105 #[clap(
107 short = 'p',
108 long,
109 default_value = "6767",
110 value_name = "PORT",
111 help = "TCP port for incoming connections"
112 )]
113 pub server_port: u16,
114
115 #[clap(
117 short,
118 long,
119 default_value = "maker",
120 value_name = "PASSWORD",
121 help = "Password required for client authentication"
122 )]
123 pub password: String,
124}