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    pub peer: String,
54    pub paths: Vec<PathBuf>,
55}
56
57#[derive(Debug, Args)]
58pub struct RecvArgs {
59    #[arg(long)]
60    pub listen: Option<SocketAddr>,
61
62    #[arg(long, value_name = "DIR")]
63    pub dest: Option<PathBuf>,
64
65    #[arg(long)]
66    pub accept_all: bool,
67}
68
69#[derive(Debug, Args)]
70pub struct DaemonArgs {
71    #[arg(long)]
72    pub listen: Option<SocketAddr>,
73
74    #[arg(long, value_name = "DIR")]
75    pub dest: Option<PathBuf>,
76}
77
78#[derive(Debug, Subcommand)]
79pub enum PeersCommand {
80    Trust { fingerprint: String },
81    Forget { fingerprint: String },
82}