浏览代码

Rework cli args

master
Dylan Baker 5 年前
父节点
当前提交
819f115ec3
共有 3 个文件被更改,包括 16 次插入16 次删除
  1. 11
    11
      Cargo.lock
  2. 1
    0
      src/cli.rs
  3. 4
    5
      src/main.rs

+ 11
- 11
Cargo.lock 查看文件

79
 version = "1.0.4"
79
 version = "1.0.4"
80
 source = "registry+https://github.com/rust-lang/crates.io-index"
80
 source = "registry+https://github.com/rust-lang/crates.io-index"
81
 
81
 
82
+[[package]]
83
+name = "bnglws-client"
84
+version = "0.1.0"
85
+dependencies = [
86
+ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
87
+ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
88
+ "reqwest 0.9.16 (registry+https://github.com/rust-lang/crates.io-index)",
89
+ "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
90
+ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
91
+]
92
+
82
 [[package]]
93
 [[package]]
83
 name = "build_const"
94
 name = "build_const"
84
 version = "0.2.1"
95
 version = "0.2.1"
340
  "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
351
  "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
341
 ]
352
 ]
342
 
353
 
343
-[[package]]
344
-name = "gist-client"
345
-version = "0.1.0"
346
-dependencies = [
347
- "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
348
- "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
349
- "reqwest 0.9.16 (registry+https://github.com/rust-lang/crates.io-index)",
350
- "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
351
- "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
352
-]
353
-
354
 [[package]]
354
 [[package]]
355
 name = "h2"
355
 name = "h2"
356
 version = "0.1.18"
356
 version = "0.1.18"

+ 1
- 0
src/cli.rs 查看文件

38
 
38
 
39
 pub fn new_snippet(matches: &ArgMatches) -> io::Result<()> {
39
 pub fn new_snippet(matches: &ArgMatches) -> io::Result<()> {
40
     let snippet = get_snippet_from_matches(matches)?;
40
     let snippet = get_snippet_from_matches(matches)?;
41
+    println!("{:?}", snippet);
41
     let config = get_server_config_from_matches(matches);
42
     let config = get_server_config_from_matches(matches);
42
 
43
 
43
     match create_snippet(snippet, &config) {
44
     match create_snippet(snippet, &config) {

+ 4
- 5
src/main.rs 查看文件

4
 extern crate serde;
4
 extern crate serde;
5
 extern crate serde_json;
5
 extern crate serde_json;
6
 
6
 
7
-use clap::{App, Arg, SubCommand};
7
+use clap::{App, AppSettings, Arg, SubCommand};
8
 use std::io;
8
 use std::io;
9
 
9
 
10
 mod cli;
10
 mod cli;
12
 
12
 
13
 fn main() -> io::Result<()> {
13
 fn main() -> io::Result<()> {
14
     let matches = App::new("snippet")
14
     let matches = App::new("snippet")
15
-        .version("0.0.1")
15
+        .version("0.1.0")
16
+        .setting(AppSettings::ArgRequiredElseHelp)
16
         .subcommand(
17
         .subcommand(
17
             SubCommand::with_name("new")
18
             SubCommand::with_name("new")
18
                 .about("Creates a new snippet")
19
                 .about("Creates a new snippet")
19
                 .arg(
20
                 .arg(
20
                     Arg::with_name("name")
21
                     Arg::with_name("name")
21
-                        .long("name")
22
-                        .short("n")
23
-                        .takes_value(true)
22
+                        .index(1)
24
                         .required(true)
23
                         .required(true)
25
                         .help("The name of the snippet"),
24
                         .help("The name of the snippet"),
26
                 )
25
                 )

正在加载...
取消
保存