The CLI frontend to a gist server written in Rust
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.

main.rs 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. extern crate chrono;
  2. extern crate clap;
  3. extern crate reqwest;
  4. extern crate serde;
  5. extern crate serde_json;
  6. use clap::{App, AppSettings, Arg, SubCommand};
  7. use std::io;
  8. mod cli;
  9. mod client;
  10. fn main() -> io::Result<()> {
  11. let matches = App::new("snippet")
  12. .version("0.1.0")
  13. .setting(AppSettings::ArgRequiredElseHelp)
  14. .subcommand(
  15. SubCommand::with_name("new")
  16. .about("Creates a new snippet")
  17. .arg(
  18. Arg::with_name("name")
  19. .index(1)
  20. .required(true)
  21. .help("The name of the snippet"),
  22. )
  23. .arg(
  24. Arg::with_name("file")
  25. .long("file")
  26. .short("file")
  27. .takes_value(true)
  28. .help("The file to use as the body of the snippet"),
  29. )
  30. .arg(
  31. Arg::with_name("filetype")
  32. .long("filetype")
  33. .short("t")
  34. .takes_value(true)
  35. .default_value("")
  36. .help("The filetype to use for syntax highlighting"),
  37. )
  38. .arg(
  39. Arg::with_name("hostname")
  40. .long("hostname")
  41. .short("s")
  42. .takes_value(true)
  43. .default_value("bngl.ws")
  44. .help("The hostname of the server to post your snippet to"),
  45. )
  46. .arg(
  47. Arg::with_name("protocol")
  48. .long("protocol")
  49. .short("c")
  50. .takes_value(true)
  51. .possible_values(&["http", "https"])
  52. .default_value("https")
  53. .help("The transport protocol to use"),
  54. )
  55. .arg(
  56. Arg::with_name("port")
  57. .long("port")
  58. .short("p")
  59. .takes_value(true)
  60. .default_value("80")
  61. .help("The transport protocol to use"),
  62. ),
  63. )
  64. .get_matches();
  65. if let Some(matches) = matches.subcommand_matches("new") {
  66. cli::new_snippet(&matches)?;
  67. }
  68. Ok(())
  69. }