//! Arg parsing and process info use super::*; use std::fmt; lazy_static!{ static ref EXEC: String = std::env::args().next().unwrap(); } pub fn program_name() -> &'static str { &EXEC[..] } /// Program usage #[derive(Debug)] pub struct Usage; impl Usage { pub fn print_and_exit(self, code: i32) -> ! { if code == 0 { print!("{}", self); } else { eprint!("{}", self); } std::process::exit(code) } } fn splash(f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "transfer v{} - simple network file transfer", env!("CARGO_PKG_VERSION"))?; writeln!(f, " written by {} with <3. License GPL3+", env!("CARGO_PKG_AUTHORS"))?; writeln!(f, "") } impl fmt::Display for Usage { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { splash(f)?; writeln!(f, "Usage: {} S --send|--recv [OPTIONS] ", program_name())?; writeln!(f, "Usage: {} C --send|--recv [OPTIONS] ", program_name())?; writeln!(f, "Usage: {} --help", program_name())?; writeln!(f, "\nNetworking mode:")?; writeln!(f, " S: Server mode. Bind to an address/port")?; writeln!(f, " C: Client mode. Connect to a listening address/port")?; writeln!(f, "\nSEND OPTIONS:")?; writeln!(f, " -e\t\t\tEncrypt file(s)")?; writeln!(f, " -c\t\t\tCompress files")?; writeln!(f, " --buffer-size \tSize of file buffer")?; writeln!(f, " -a\t\t\tSend file names")?; writeln!(f, " -k\t\t\tSupport continuation of failed downloads")?; writeln!(f, "\nRECV OPTIONS:")?; writeln!(f, " -i\t\t\tAsk before starting downloads")?; writeln!(f, " -k\t\t\tContinue a previously started download")?; Ok(()) } } /// The process parsed from command line #[derive(Debug, Clone, PartialEq, Eq)] pub struct Process { /// The parsed config (includes mode) pub config: config::Config, /// The listed paths pub paths: Vec, /// Use stdin/out pub stdio: bool, } /// An operation parsed from command line arguments #[derive(Debug, Clone, PartialEq, Eq)] pub enum Op { Process(Box), Help, } mod parse;