cmd_upload.rs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. use super::clap::{App, Arg, ArgMatches, SubCommand};
  2. use app::SEND_DEF_HOST;
  3. /// The upload command.
  4. pub struct CmdUpload<'a> {
  5. matches: &'a ArgMatches<'a>,
  6. }
  7. impl<'a: 'b, 'b> CmdUpload<'a> {
  8. /// Build the sub command definition.
  9. pub fn build<'y, 'z>() -> App<'y, 'z> {
  10. SubCommand::with_name("upload")
  11. .about("Upload files")
  12. .visible_alias("u")
  13. .visible_alias("up")
  14. .arg(Arg::with_name("FILE")
  15. .help("The file to upload")
  16. .required(true)
  17. .multiple(false))
  18. .arg(Arg::with_name("host")
  19. .long("host")
  20. .short("h")
  21. .alias("server")
  22. .value_name("URL")
  23. .default_value(SEND_DEF_HOST)
  24. .help("The Send host to upload to"))
  25. .arg(Arg::with_name("open")
  26. .long("open")
  27. .short("o")
  28. .help("Open the share link in your browser"))
  29. .arg(Arg::with_name("c")
  30. .long("copy")
  31. .short("c")
  32. .help("Copy the share link to your clipboard"))
  33. }
  34. /// Parse CLI arguments, from the given parent command matches.
  35. pub fn parse(parent: &'a ArgMatches<'a>) -> Option<CmdUpload<'a>> {
  36. parent.subcommand_matches("upload")
  37. .map(|matches| CmdUpload { matches })
  38. }
  39. /// Get the selected file to upload.
  40. pub fn file(&'a self) -> &'a str {
  41. self.matches.value_of("FILE")
  42. .expect("no file specified to upload")
  43. }
  44. }