summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
blob: 61399f746f50991338523af4b528fc01c3b59b13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use clap::App;
use clap::Arg;
use clap::crate_authors;
use clap::crate_version;

pub fn server_app<'a>() -> App<'a, 'a> {
    App::new("fss")
        .author(crate_authors!())
        .version(crate_version!())
        .about("Filesystemsearch")

        .arg(self::common::arg_server_addr())
        .arg(self::common::arg_server_port())
}


pub fn client_app<'a>() -> App<'a, 'a> {
    App::new("fss")
        .author(crate_authors!())
        .version(crate_version!())
        .about("Filesystemsearch")

        .arg(self::common::arg_server_addr())
        .arg(self::common::arg_server_port())

        .subcommand(App::new("index")
            .version(crate_version!())
            .about("Index a file")
            .arg(Arg::with_name("file")
                .required(true)
                .multiple(false)
                .value_name("FILE")
                .help("Index this file")
            )
        )

        .subcommand(App::new("search")
            .version(crate_version!())
            .about("Search for a file")
            .arg(Arg::with_name("term")
                .required(true)
                .multiple(true)
                .value_name("TERM")
                .help("Search with these terms")
            )
        )
}

mod common {
    use clap::Arg;

    pub fn arg_server_addr<'a, 'b>() -> Arg<'a, 'b> {
        Arg::with_name("server_addr")
            .required(false)
            .multiple(false)
            .value_name("ADDR")
            .help("The address of the server")
    }

    pub fn arg_server_port<'a, 'b>() -> Arg<'a, 'b> {
        Arg::with_name("server_port")
            .required(false)
            .multiple(false)
            .value_name("PORT")
            .help("The port of the server")
    }
}