You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.1 KiB

//! 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 <bind> --send|--recv [OPTIONS] <file...>", program_name())?;
writeln!(f, "Usage: {} C <connect> --send|--recv [OPTIONS] <output...>", 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 <bytes>\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<String>,
/// Use stdin/out
pub stdio: bool,
}
/// An operation parsed from command line arguments
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Op
{
Process(Box<Process>),
Help,
}
mod parse;