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;
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,
    )
}