Переглянути джерело

Rename Gists to Snippets

master
Dylan Baker 5 роки тому
джерело
коміт
f98f76899e
3 змінених файлів з 21 додано та 21 видалено
  1. 7
    7
      src/cli.rs
  2. 8
    8
      src/client.rs
  3. 6
    6
      src/main.rs

+ 7
- 7
src/cli.rs Переглянути файл

2
 use std::fs;
2
 use std::fs;
3
 use std::io;
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
     let title = matches.value_of("name").unwrap();
8
     let title = matches.value_of("name").unwrap();
9
     let input = matches.value_of("file");
9
     let input = matches.value_of("file");
10
     let filetype = matches.value_of("filetype").unwrap();
10
     let filetype = matches.value_of("filetype").unwrap();
17
     let mut body = String::new();
17
     let mut body = String::new();
18
     rdr.read_to_string(&mut body)?;
18
     rdr.read_to_string(&mut body)?;
19
 
19
 
20
-    Ok(OutgoingGist {
20
+    Ok(OutgoingSnippet {
21
         title: title.to_string(),
21
         title: title.to_string(),
22
         body,
22
         body,
23
         filetype: filetype.to_string(),
23
         filetype: filetype.to_string(),
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
     let config = get_server_config_from_matches(matches);
41
     let config = get_server_config_from_matches(matches);
42
 
42
 
43
-    match create_gist(gist, &config) {
43
+    match create_snippet(snippet, &config) {
44
         Ok(resp) => println!(
44
         Ok(resp) => println!(
45
-            "Success! Your new gist is available at {}://{}:{}/gists/{}",
45
+            "Success! Your new snippet is available at {}://{}:{}/snippets/{}",
46
             config.protocol, config.hostname, config.port, resp.id
46
             config.protocol, config.hostname, config.port, resp.id
47
         ),
47
         ),
48
         Err(err) => println!("{}", err),
48
         Err(err) => println!("{}", err),

+ 8
- 8
src/client.rs Переглянути файл

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

+ 6
- 6
src/main.rs Переглянути файл

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

Завантаження…
Відмінити
Зберегти