The CLI frontend to a gist server written in Rust
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

cli.rs 701B

12345678910111213141516171819202122232425262728
  1. use clap::ArgMatches;
  2. use std::fs;
  3. use std::io;
  4. use crate::client::create_gist;
  5. pub fn new_gist(matches: &ArgMatches) -> io::Result<()> {
  6. let title = matches.value_of("title").unwrap();
  7. let input = matches.value_of("input");
  8. let mut rdr: Box<io::Read> = match input {
  9. Some(file) => Box::new(fs::File::open(file)?),
  10. None => Box::new(io::stdin()),
  11. };
  12. let mut body = String::new();
  13. rdr.read_to_string(&mut body)?;
  14. match create_gist(title, &body) {
  15. Ok(resp) => println!(
  16. "Success! Your new gist is available at http://localhost:8000/gists/{}",
  17. resp.id
  18. ),
  19. Err(err) => println!("{}", err),
  20. }
  21. Ok(())
  22. }