1use anyhow::Result;
2use camino::Utf8PathBuf;
3use clap::{Parser, Subcommand};
4
5use crate::cmd;
6use crate::config::IconsMode;
7
8#[derive(Parser, Debug)]
9#[command(version, about, long_about = None)]
10pub struct Cli {
11 #[arg(short, long, env = "YUI_SOURCE", global = true)]
13 pub source: Option<Utf8PathBuf>,
14
15 #[arg(short, long, action = clap::ArgAction::Count, global = true)]
17 pub verbose: u8,
18
19 #[command(subcommand)]
20 pub command: Command,
21}
22
23#[derive(Subcommand, Debug)]
24pub enum Command {
25 Init {
27 #[arg(long)]
29 git_hooks: bool,
30 },
31
32 Apply {
34 #[arg(long)]
35 dry_run: bool,
36 },
37
38 Render {
40 #[arg(long)]
42 check: bool,
43 #[arg(long)]
44 dry_run: bool,
45 },
46
47 Link {
49 #[arg(long)]
50 dry_run: bool,
51 },
52
53 Unlink { paths: Vec<Utf8PathBuf> },
55
56 Status {
58 #[arg(long, value_name = "MODE")]
60 icons: Option<IconsMode>,
61 #[arg(long)]
63 no_color: bool,
64 },
65
66 List {
68 #[arg(long)]
70 all: bool,
71 #[arg(long, value_name = "MODE")]
73 icons: Option<IconsMode>,
74 #[arg(long)]
76 no_color: bool,
77 },
78
79 Absorb {
81 target: Utf8PathBuf,
82 #[arg(long)]
83 dry_run: bool,
84 },
85
86 Doctor,
88
89 GcBackup {
91 #[arg(long)]
93 older_than: Option<String>,
94 },
95}
96
97impl Cli {
98 pub fn run(self) -> Result<()> {
99 let source = self.source;
100 match self.command {
101 Command::Init { git_hooks } => cmd::init(source, git_hooks),
102 Command::Apply { dry_run } => cmd::apply(source, dry_run),
103 Command::Render { check, dry_run } => cmd::render(source, check, dry_run),
104 Command::Link { dry_run } => cmd::link(source, dry_run),
105 Command::Unlink { paths } => cmd::unlink(source, paths),
106 Command::Status { icons, no_color } => cmd::status(source, icons, no_color),
107 Command::List {
108 all,
109 icons,
110 no_color,
111 } => cmd::list(source, all, icons, no_color),
112 Command::Absorb { target, dry_run } => cmd::absorb(source, target, dry_run),
113 Command::Doctor => cmd::doctor(source),
114 Command::GcBackup { older_than } => cmd::gc_backup(source, older_than),
115 }
116 }
117}