Browse Source

Add filetype to gists

master
Dylan Baker 5 years ago
parent
commit
35b26f8d75
5 changed files with 48 additions and 2 deletions
  1. 28
    0
      Cargo.lock
  2. 1
    0
      Cargo.toml
  3. 2
    1
      src/cli.rs
  4. 9
    1
      src/client.rs
  5. 8
    0
      src/main.rs

+ 28
- 0
Cargo.lock View File

@@ -108,6 +108,17 @@ name = "cfg-if"
108 108
 version = "0.1.7"
109 109
 source = "registry+https://github.com/rust-lang/crates.io-index"
110 110
 
111
+[[package]]
112
+name = "chrono"
113
+version = "0.4.6"
114
+source = "registry+https://github.com/rust-lang/crates.io-index"
115
+dependencies = [
116
+ "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
117
+ "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
118
+ "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
119
+ "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
120
+]
121
+
111 122
 [[package]]
112 123
 name = "clap"
113 124
 version = "2.33.0"
@@ -333,6 +344,7 @@ dependencies = [
333 344
 name = "gist-client"
334 345
 version = "0.1.0"
335 346
 dependencies = [
347
+ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
336 348
  "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
337 349
  "reqwest 0.9.16 (registry+https://github.com/rust-lang/crates.io-index)",
338 350
  "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -594,6 +606,19 @@ name = "nodrop"
594 606
 version = "0.1.13"
595 607
 source = "registry+https://github.com/rust-lang/crates.io-index"
596 608
 
609
+[[package]]
610
+name = "num-integer"
611
+version = "0.1.39"
612
+source = "registry+https://github.com/rust-lang/crates.io-index"
613
+dependencies = [
614
+ "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
615
+]
616
+
617
+[[package]]
618
+name = "num-traits"
619
+version = "0.2.6"
620
+source = "registry+https://github.com/rust-lang/crates.io-index"
621
+
597 622
 [[package]]
598 623
 name = "num_cpus"
599 624
 version = "1.10.0"
@@ -1404,6 +1429,7 @@ dependencies = [
1404 1429
 "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
1405 1430
 "checksum cc 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a0c56216487bb80eec9c4516337b2588a4f2a2290d72a1416d930e4dcdb0c90d"
1406 1431
 "checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4"
1432
+"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"
1407 1433
 "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
1408 1434
 "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
1409 1435
 "checksum cookie 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1465f8134efa296b4c19db34d909637cb2bf0f7aaf21299e23e18fa29ac557cf"
@@ -1457,6 +1483,8 @@ dependencies = [
1457 1483
 "checksum native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e"
1458 1484
 "checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
1459 1485
 "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
1486
+"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
1487
+"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
1460 1488
 "checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba"
1461 1489
 "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
1462 1490
 "checksum openssl 0.10.21 (registry+https://github.com/rust-lang/crates.io-index)" = "615b325b964d8fb0533e7fad5867f63677bbc79a274c9cd7a19443e1a6fcdd9e"

+ 1
- 0
Cargo.toml View File

@@ -5,6 +5,7 @@ authors = ["Dylan Baker"]
5 5
 edition = "2018"
6 6
 
7 7
 [dependencies]
8
+chrono = { version = "0.4.6", features = ["serde"] }
8 9
 clap = "2.33.0"
9 10
 reqwest = "0.9.16"
10 11
 serde = { version = "1.0.90", features = ["derive"] }

+ 2
- 1
src/cli.rs View File

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

+ 9
- 1
src/client.rs View File

@@ -1,9 +1,11 @@
1
+use chrono::NaiveDateTime;
1 2
 use serde::{Deserialize, Serialize};
2 3
 
3 4
 #[derive(Serialize, Deserialize, Debug)]
4 5
 pub struct OutgoingGist {
5 6
     pub title: String,
6 7
     pub body: String,
8
+    pub filetype: Option<String>,
7 9
 }
8 10
 
9 11
 #[derive(Serialize, Deserialize, Debug)]
@@ -11,13 +13,19 @@ pub struct IncomingGist {
11 13
     pub id: i32,
12 14
     pub title: String,
13 15
     pub body: String,
16
+    pub created_at: NaiveDateTime,
14 17
 }
15 18
 
16
-pub fn create_gist(title: &str, body: &str) -> Result<IncomingGist, Box<std::error::Error>> {
19
+pub fn create_gist(
20
+    title: &str,
21
+    body: &str,
22
+    filetype: Option<&str>,
23
+) -> Result<IncomingGist, Box<std::error::Error>> {
17 24
     let client = reqwest::Client::new();
18 25
     let gist = OutgoingGist {
19 26
         title: title.to_string(),
20 27
         body: body.to_string(),
28
+        filetype: filetype.map(|ft| ft.to_string()),
21 29
     };
22 30
 
23 31
     let resp: IncomingGist = client

+ 8
- 0
src/main.rs View File

@@ -1,3 +1,4 @@
1
+extern crate chrono;
1 2
 extern crate clap;
2 3
 extern crate reqwest;
3 4
 extern crate serde;
@@ -29,6 +30,13 @@ fn main() -> io::Result<()> {
29 30
                         .short("file")
30 31
                         .takes_value(true)
31 32
                         .help("The file to use as the body of the gist"),
33
+                )
34
+                .arg(
35
+                    Arg::with_name("filetype")
36
+                        .long("filetype")
37
+                        .short("p")
38
+                        .takes_value(true)
39
+                        .help("The filetype to use for syntax highlighting"),
32 40
                 ),
33 41
         )
34 42
         .get_matches();

Loading…
Cancel
Save