Browse Source

Initial commit

master
Dylan Baker 5 years ago
commit
388e6be90b
5 changed files with 1615 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 1546
    0
      Cargo.lock
  3. 9
    0
      Cargo.toml
  4. 21
    0
      src/cli.rs
  5. 37
    0
      src/main.rs

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
1
+/target
2
+**/*.rs.bk

+ 1546
- 0
Cargo.lock
File diff suppressed because it is too large
View File


+ 9
- 0
Cargo.toml View File

@@ -0,0 +1,9 @@
1
+[package]
2
+name = "gist-client"
3
+version = "0.1.0"
4
+authors = ["Dylan Baker"]
5
+edition = "2018"
6
+
7
+[dependencies]
8
+clap = "2.33.0"
9
+reqwest = "0.9.16"

+ 21
- 0
src/cli.rs View File

@@ -0,0 +1,21 @@
1
+use clap::ArgMatches;
2
+use std::fs;
3
+use std::io;
4
+
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
+
9
+    let mut rdr: Box<io::Read> = match input {
10
+        Some(file) => Box::new(fs::File::open(file)?),
11
+        None => Box::new(io::stdin()),
12
+    };
13
+
14
+    let mut body = String::new();
15
+    rdr.read_to_string(&mut body)?;
16
+
17
+    println!("title: {}", title);
18
+    println!("body: {}", body);
19
+
20
+    Ok(())
21
+}

+ 37
- 0
src/main.rs View File

@@ -0,0 +1,37 @@
1
+extern crate clap;
2
+
3
+use clap::{App, Arg, SubCommand};
4
+use std::io;
5
+
6
+mod cli;
7
+
8
+fn main() -> io::Result<()> {
9
+    let matches = App::new("gist")
10
+        .version("0.0.1")
11
+        .subcommand(
12
+            SubCommand::with_name("new")
13
+                .about("Creates a new gist")
14
+                .arg(
15
+                    Arg::with_name("title")
16
+                        .long("title")
17
+                        .short("t")
18
+                        .takes_value(true)
19
+                        .required(true)
20
+                        .help("The title of the gist"),
21
+                )
22
+                .arg(
23
+                    Arg::with_name("file")
24
+                        .long("file")
25
+                        .short("file")
26
+                        .takes_value(true)
27
+                        .help("The file to use as the body of the gist"),
28
+                ),
29
+        )
30
+        .get_matches();
31
+
32
+    if let Some(matches) = matches.subcommand_matches("new") {
33
+        cli::new_gist(&matches)?;
34
+    }
35
+
36
+    Ok(())
37
+}

Loading…
Cancel
Save