12345678910111213141516171819202122232425262728 |
- use clap::ArgMatches;
- use std::fs;
- use std::io;
-
- use crate::client::create_gist;
-
- pub fn new_gist(matches: &ArgMatches) -> io::Result<()> {
- let title = matches.value_of("title").unwrap();
- let input = matches.value_of("input");
-
- let mut rdr: Box<io::Read> = match input {
- Some(file) => Box::new(fs::File::open(file)?),
- None => Box::new(io::stdin()),
- };
-
- let mut body = String::new();
- rdr.read_to_string(&mut body)?;
-
- match create_gist(title, &body) {
- Ok(resp) => println!(
- "Success! Your new gist is available at http://localhost:8000/gists/{}",
- resp.id
- ),
- Err(err) => println!("{}", err),
- }
-
- Ok(())
- }
|