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 value_name = "PATH",
74 help = "Remote file path (default: same filename as local)"
75 )]
76 pub remote_path: Option<PathBuf>,
77
78 #[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 #[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 #[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 #[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}