Rust · 2337 bytes Raw Blame History
1 use clap::{Parser, Subcommand};
2 use anyhow::Result;
3 use tracing::{info, Level};
4 use tracing_subscriber::FmtSubscriber;
5
6 mod commands;
7 mod config;
8 mod client;
9
10 use commands::{InitCommand, JoinCommand, UploadCommand, DownloadCommand, ListCommand, StatusCommand, EncryptCommand, DecryptCommand, Command};
11
12 #[derive(Parser)]
13 #[command(name = "zephyrfs")]
14 #[command(about = "A distributed P2P storage system")]
15 #[command(version)]
16 struct Cli {
17 #[command(subcommand)]
18 command: Commands,
19
20 #[arg(short, long, global = true)]
21 verbose: bool,
22
23 #[arg(short, long, global = true)]
24 config: Option<String>,
25 }
26
27 #[derive(Subcommand)]
28 enum Commands {
29 /// Initialize a new ZephyrFS node
30 Init(InitCommand),
31
32 /// Join an existing ZephyrFS network
33 Join(JoinCommand),
34
35 /// Upload a file to the network
36 Upload(UploadCommand),
37
38 /// Download a file from the network
39 Download(DownloadCommand),
40
41 /// List files in the network
42 #[command(alias = "ls")]
43 List(ListCommand),
44
45 /// Show node status and network information
46 Status(StatusCommand),
47
48 /// Encrypt a file with password
49 Encrypt(EncryptCommand),
50
51 /// Decrypt a file with password
52 Decrypt(DecryptCommand),
53 }
54
55 #[tokio::main]
56 async fn main() -> Result<()> {
57 let cli = Cli::parse();
58
59 // Initialize logging
60 let level = if cli.verbose { Level::DEBUG } else { Level::INFO };
61 let subscriber = FmtSubscriber::builder()
62 .with_max_level(level)
63 .finish();
64 tracing::subscriber::set_global_default(subscriber)
65 .expect("setting default subscriber failed");
66
67 info!("Starting ZephyrFS CLI");
68
69 // Load configuration
70 let config_path = cli.config.as_deref();
71 let config = config::Config::load(config_path)?;
72
73 // Execute command
74 match cli.command {
75 Commands::Init(cmd) => cmd.execute(&config).await,
76 Commands::Join(cmd) => cmd.execute(&config).await,
77 Commands::Upload(cmd) => cmd.execute(&config).await,
78 Commands::Download(cmd) => cmd.execute(&config).await,
79 Commands::List(cmd) => cmd.execute(&config).await,
80 Commands::Status(cmd) => cmd.execute(&config).await,
81 Commands::Encrypt(cmd) => cmd.execute(&config).await,
82 Commands::Decrypt(cmd) => cmd.execute(&config).await,
83 }
84 }