1
use clap::{Parser, Subcommand};
2

            
3
#[derive(Parser)]
4
#[command(author, version, about, long_about=None)]
5
struct Cli {
6
    #[command(subcommand)]
7
    command: Option<Commands>,
8

            
9
    /// Turn debugging information on
10
    #[arg(short, long, action = clap::ArgAction::Count)]
11
    debug: u8,
12
}
13

            
14
#[derive(Subcommand)]
15
enum Commands {
16
    /// Ascend directory by count or path component
17
    Cd {
18
        /// Number of levels to ascend or directory to ascend to
19
        target: cdup::NumberOrString,
20
    },
21
    /// Give completion hint for given term
22
    Hint {
23
        /// Term to print hint for
24
        term: Option<String>,
25
    },
26
    /// Initialize function for shell
27
    Init {
28
        /// Function name to use
29
        #[arg(short, long, default_value = "up")]
30
        alias: String,
31
        /// Used shell
32
        hint: Option<String>,
33
    },
34
}
35

            
36
fn main() {
37
    let cli = Cli::parse();
38

            
39
    match &cli.command {
40
        Some(Commands::Cd { target }) => cdup::run_cd(target),
41
        Some(Commands::Hint { term }) => cdup::run_hint(term.as_deref()),
42
        Some(Commands::Init { alias, hint }) => cdup::run_init(alias, hint),
43
        None => {}
44
    }
45
}