Skip to main content

ferry_cli/
lib.rs

1use std::net::SocketAddr;
2use std::path::PathBuf;
3
4use clap::{Args, CommandFactory, Parser, Subcommand};
5
6#[derive(Debug, Parser)]
7#[command(name = "ferry", version, about = "Local-network file transfer")]
8pub struct Cli {
9    #[arg(long, global = true)]
10    pub port: Option<u16>,
11
12    #[arg(long, global = true)]
13    pub bind: Option<String>,
14
15    #[arg(long, global = true)]
16    pub json: bool,
17
18    #[arg(long, global = true)]
19    pub no_discovery: bool,
20
21    #[arg(short, long, global = true)]
22    pub quiet: bool,
23
24    #[arg(short, long, action = clap::ArgAction::Count, global = true)]
25    pub verbose: u8,
26
27    #[command(subcommand)]
28    pub command: Option<Command>,
29}
30
31impl Cli {
32    pub fn clap_command() -> clap::Command {
33        Self::command()
34    }
35}
36
37#[derive(Debug, Subcommand)]
38pub enum Command {
39    Send(SendArgs),
40    Recv(RecvArgs),
41    Peers {
42        #[command(subcommand)]
43        command: Option<PeersCommand>,
44    },
45    Daemon(DaemonArgs),
46    Config,
47    #[command(about = "Print the local alias and device fingerprint")]
48    Identity,
49    Version,
50    Tui,
51}
52
53#[derive(Debug, Args)]
54pub struct SendArgs {
55    #[arg(
56        long,
57        value_name = "FINGERPRINT",
58        help = "Require the receiver certificate to match this full fingerprint"
59    )]
60    pub fingerprint: Option<String>,
61
62    #[arg(
63        long,
64        value_name = "FILE",
65        help = "Read an explicit transfer PSK from a file"
66    )]
67    pub psk_file: Option<PathBuf>,
68
69    pub peer: String,
70    pub paths: Vec<PathBuf>,
71}
72
73#[derive(Debug, Args)]
74pub struct RecvArgs {
75    #[arg(long)]
76    pub listen: Option<SocketAddr>,
77
78    #[arg(long, value_name = "DIR")]
79    pub dest: Option<PathBuf>,
80
81    #[arg(long)]
82    pub accept_all: bool,
83
84    #[arg(
85        long,
86        value_name = "FILE",
87        help = "Require an explicit transfer PSK read from a file"
88    )]
89    pub psk_file: Option<PathBuf>,
90}
91
92#[derive(Debug, Args)]
93pub struct DaemonArgs {
94    #[arg(long)]
95    pub listen: Option<SocketAddr>,
96
97    #[arg(long, value_name = "DIR")]
98    pub dest: Option<PathBuf>,
99
100    #[arg(
101        long,
102        value_name = "FILE",
103        help = "Require an explicit transfer PSK read from a file"
104    )]
105    pub psk_file: Option<PathBuf>,
106}
107
108#[derive(Debug, Subcommand)]
109pub enum PeersCommand {
110    Trust { fingerprint: String },
111    Forget { fingerprint: String },
112}