dot_over/cli/
mod.rs

1use std::path::PathBuf;
2
3use anyhow::Result;
4use clap::{crate_name, Parser, Subcommand};
5
6use crate::ui::style::clap_styles;
7
8mod add;
9mod apply;
10mod list;
11mod show;
12mod status;
13
14#[derive(Parser, Debug)]
15#[clap(
16    author,
17    version,
18    about,
19    name = crate_name!(),
20    long_about = None,
21    styles = clap_styles(),
22	// after_help = "over allows you to version your configuration files and workspaces settings",
23)]
24pub struct CLI {
25    #[clap(
26        long,
27        short = 'H',
28        global = true,
29        required = false,
30        env = "OVER_HOME",
31        help = "Configuration and overlays root"
32    )]
33    home: PathBuf,
34
35    #[clap(long, short, global = true, help = "Toggle debug traces")]
36    debug: bool,
37
38    #[clap(long, short, global = true, help = "Toggle verbose output")]
39    verbose: bool,
40
41    #[clap(subcommand)]
42    cmd: Option<Commands>,
43}
44
45#[derive(Subcommand, Debug)]
46pub enum Commands {
47    #[clap(name = "add", about = "Add a file to an overlay")]
48    Add(add::Params),
49
50    #[clap(name = "list", about = "List known overlays", alias = "ls")]
51    List(list::Params),
52
53    #[clap(name = "show", about = "Display details about an overlay")]
54    Show(show::Params),
55
56    #[clap(name = "apply", about = "Apply a given overlay")]
57    Apply(apply::Params),
58
59    #[clap(
60        name = "status",
61        about = "Get the current repository/directory overlays status"
62    )]
63    Status,
64}
65
66pub async fn main() -> Result<()> {
67    let args = CLI::parse();
68    match args.cmd {
69        Some(Commands::Add(ref opt)) => {
70            add::execute(&args, opt).await?;
71        }
72
73        Some(Commands::List(ref opt)) => {
74            list::execute(&args, opt).await?;
75        }
76        Some(Commands::Apply(ref opt)) => {
77            apply::execute(&args, opt).await?;
78        }
79        Some(Commands::Show(ref opt)) => {
80            show::execute(&args, opt).await?;
81        }
82        Some(Commands::Status) => {
83            status::execute(&args).await?;
84        }
85        None => {
86            println!("args: {:?}", args);
87        }
88    }
89    Ok(())
90}