Browse Source

Rename Gists to Snippets

master
Dylan Baker 5 years ago
parent
commit
f98f76899e
3 changed files with 21 additions and 21 deletions
  1. 7
    7
      src/cli.rs
  2. 8
    8
      src/client.rs
  3. 6
    6
      src/main.rs

+ 7
- 7
src/cli.rs View File

@@ -2,9 +2,9 @@ use clap::ArgMatches;
2 2
 use std::fs;
3 3
 use std::io;
4 4
 
5
-use crate::client::{create_gist, OutgoingGist, ServerConfig};
5
+use crate::client::{create_snippet, OutgoingSnippet, ServerConfig};
6 6
 
7
-fn get_gist_from_matches(matches: &ArgMatches) -> io::Result<OutgoingGist> {
7
+fn get_snippet_from_matches(matches: &ArgMatches) -> io::Result<OutgoingSnippet> {
8 8
     let title = matches.value_of("name").unwrap();
9 9
     let input = matches.value_of("file");
10 10
     let filetype = matches.value_of("filetype").unwrap();
@@ -17,7 +17,7 @@ fn get_gist_from_matches(matches: &ArgMatches) -> io::Result<OutgoingGist> {
17 17
     let mut body = String::new();
18 18
     rdr.read_to_string(&mut body)?;
19 19
 
20
-    Ok(OutgoingGist {
20
+    Ok(OutgoingSnippet {
21 21
         title: title.to_string(),
22 22
         body,
23 23
         filetype: filetype.to_string(),
@@ -36,13 +36,13 @@ fn get_server_config_from_matches(matches: &ArgMatches) -> ServerConfig {
36 36
     }
37 37
 }
38 38
 
39
-pub fn new_gist(matches: &ArgMatches) -> io::Result<()> {
40
-    let gist = get_gist_from_matches(matches)?;
39
+pub fn new_snippet(matches: &ArgMatches) -> io::Result<()> {
40
+    let snippet = get_snippet_from_matches(matches)?;
41 41
     let config = get_server_config_from_matches(matches);
42 42
 
43
-    match create_gist(gist, &config) {
43
+    match create_snippet(snippet, &config) {
44 44
         Ok(resp) => println!(
45
-            "Success! Your new gist is available at {}://{}:{}/gists/{}",
45
+            "Success! Your new snippet is available at {}://{}:{}/snippets/{}",
46 46
             config.protocol, config.hostname, config.port, resp.id
47 47
         ),
48 48
         Err(err) => println!("{}", err),

+ 8
- 8
src/client.rs View File

@@ -2,7 +2,7 @@ use chrono::NaiveDateTime;
2 2
 use serde::{Deserialize, Serialize};
3 3
 
4 4
 #[derive(Serialize, Deserialize, Debug)]
5
-pub struct OutgoingGist {
5
+pub struct OutgoingSnippet {
6 6
     pub title: String,
7 7
     pub body: String,
8 8
     pub formatted_body: String,
@@ -10,7 +10,7 @@ pub struct OutgoingGist {
10 10
 }
11 11
 
12 12
 #[derive(Serialize, Deserialize, Debug)]
13
-pub struct IncomingGist {
13
+pub struct IncomingSnippet {
14 14
     pub id: i32,
15 15
     pub title: String,
16 16
     pub body: String,
@@ -24,17 +24,17 @@ pub struct ServerConfig {
24 24
     pub port: i32,
25 25
 }
26 26
 
27
-pub fn create_gist(
28
-    gist: OutgoingGist,
27
+pub fn create_snippet(
28
+    snippet: OutgoingSnippet,
29 29
     config: &ServerConfig,
30
-) -> Result<IncomingGist, Box<std::error::Error>> {
30
+) -> Result<IncomingSnippet, Box<std::error::Error>> {
31 31
     let client = reqwest::Client::new();
32
-    let resp: IncomingGist = client
32
+    let resp: IncomingSnippet = client
33 33
         .post(&format!(
34
-            "{}://{}:{}/api/gists",
34
+            "{}://{}:{}/api/snippets",
35 35
             config.protocol, config.hostname, config.port,
36 36
         ))
37
-        .json(&gist)
37
+        .json(&snippet)
38 38
         .send()?
39 39
         .json()?;
40 40
 

+ 6
- 6
src/main.rs View File

@@ -11,25 +11,25 @@ mod cli;
11 11
 mod client;
12 12
 
13 13
 fn main() -> io::Result<()> {
14
-    let matches = App::new("gist")
14
+    let matches = App::new("snippet")
15 15
         .version("0.0.1")
16 16
         .subcommand(
17 17
             SubCommand::with_name("new")
18
-                .about("Creates a new gist")
18
+                .about("Creates a new snippet")
19 19
                 .arg(
20 20
                     Arg::with_name("name")
21 21
                         .long("name")
22 22
                         .short("n")
23 23
                         .takes_value(true)
24 24
                         .required(true)
25
-                        .help("The name of the gist"),
25
+                        .help("The name of the snippet"),
26 26
                 )
27 27
                 .arg(
28 28
                     Arg::with_name("file")
29 29
                         .long("file")
30 30
                         .short("file")
31 31
                         .takes_value(true)
32
-                        .help("The file to use as the body of the gist"),
32
+                        .help("The file to use as the body of the snippet"),
33 33
                 )
34 34
                 .arg(
35 35
                     Arg::with_name("filetype")
@@ -45,7 +45,7 @@ fn main() -> io::Result<()> {
45 45
                         .short("s")
46 46
                         .takes_value(true)
47 47
                         .default_value("bngl.ws")
48
-                        .help("The hostname of the server to post your gist to"),
48
+                        .help("The hostname of the server to post your snippet to"),
49 49
                 )
50 50
                 .arg(
51 51
                     Arg::with_name("protocol")
@@ -68,7 +68,7 @@ fn main() -> io::Result<()> {
68 68
         .get_matches();
69 69
 
70 70
     if let Some(matches) = matches.subcommand_matches("new") {
71
-        cli::new_gist(&matches)?;
71
+        cli::new_snippet(&matches)?;
72 72
     }
73 73
 
74 74
     Ok(())

Loading…
Cancel
Save