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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// Wildland Project
//
// Copyright © 2022 Golem Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 3 as published by
// the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

use clap::ArgAction;
use reedline_repl_rs::clap::{Arg, Command};
use reedline_repl_rs::Repl;

pub mod handler;
mod stream;
mod tests;
use handler::*;

use crate::Context;

// extend the repl with cargo commands
pub fn extend(repl: Repl<Context, anyhow::Error>) -> Repl<Context, anyhow::Error> {
    repl.with_command(
        Command::new("touch")
            .about("create empty file or modify accesstime on the existing one")
            .arg(Arg::new("path").required(true).index(1)),
        h_touch,
    )
    .with_command(
        Command::new("ls")
            .about("list directory")
            .arg(Arg::new("path").required(false).index(1)),
        h_ls,
    )
    .with_command(
        Command::new("cd")
            .about("change directory")
            .arg(Arg::new("path").required(false).index(1)),
        h_cd,
    )
    .with_command(
        Command::new("rm")
            .about("remove file")
            .arg(Arg::new("path").required(true).index(1)),
        h_rm,
    )
    .with_command(
        Command::new("rmdir")
            .about("remove directory")
            .arg(Arg::new("path").required(true))
            .arg(
                Arg::new("recursive")
                    .short('r')
                    .help("remove directories and their contents recursively")
                    .action(ArgAction::SetTrue),
            ),
        h_rmdir,
    )
    .with_command(Command::new("pwd").about("print working directory"), h_pwd)
    .with_command(
        Command::new("mkdir")
            .about("create directory")
            .arg(Arg::new("path").required(true).index(1)),
        h_mkdir,
    )
    .with_command(
        Command::new("get")
            .about("download a file")
            .arg(Arg::new("source_path").required(true).index(1))
            .arg(Arg::new("target_path").required(true).index(2)),
        h_get,
    )
    .with_command(
        Command::new("put")
            .about("upload a file")
            .arg(Arg::new("source_path").required(true).index(1))
            .arg(Arg::new("target_path").required(true).index(2)),
        h_put,
    )
    .with_command(
        Command::new("stat")
            .about("get file statistics")
            .arg(Arg::new("path").required(true).index(1)),
        h_stat,
    )
    .with_command(
        Command::new("get-path")
            .about("get path of the uuid")
            .arg(Arg::new("uuid").required(true).index(1)),
        h_get_path,
    )
    .with_command(
        Command::new("mv")
            .about("rename (move) target node from `source_path` to `target_path`")
            .arg(Arg::new("source_path").required(true).index(1))
            .arg(Arg::new("target_path").required(true).index(2)),
        h_rename,
    )
}