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    Version,
48    Tui,
49}
50
51#[derive(Debug, Args)]
52pub struct SendArgs {
53    #[arg(
54        long,
55        value_name = "FINGERPRINT",
56        help = "Require the receiver certificate to match this full fingerprint"
57    )]
58    pub fingerprint: Option<String>,
59
60    pub peer: String,
61    pub paths: Vec<PathBuf>,
62}
63
64#[derive(Debug, Args)]
65pub struct RecvArgs {
66    #[arg(long)]
67    pub listen: Option<SocketAddr>,
68
69    #[arg(long, value_name = "DIR")]
70    pub dest: Option<PathBuf>,
71
72    #[arg(long)]
73    pub accept_all: bool,
74}
75
76#[derive(Debug, Args)]
77pub struct DaemonArgs {
78    #[arg(long)]
79    pub listen: Option<SocketAddr>,
80
81    #[arg(long, value_name = "DIR")]
82    pub dest: Option<PathBuf>,
83}
84
85#[derive(Debug, Subcommand)]
86pub enum PeersCommand {
87    Trust { fingerprint: String },
88    Forget { fingerprint: String },
89}