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.
61 lines
1.5 KiB
61 lines
1.5 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: {} --send <bind> [SEND OPTIONS] <file...>", program_name())?;
|
|
writeln!(f, "Usage: {} --recv <endpoint> [RECV OPTIONS] <output...>", program_name())?;
|
|
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, " -1\t\t\tExit after 1 client has been served")?;
|
|
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(())
|
|
}
|
|
}
|