1use clap::{Parser, Subcommand};
8
9use crate::exit_code::ExitCode;
10use crate::output::OutputConfig;
11
12mod admin;
13mod alias;
14mod cat;
15mod completions;
16pub mod cp;
17pub mod diff;
18mod find;
19mod head;
20mod ls;
21mod mb;
22mod mirror;
23mod mv;
24mod pipe;
25mod quota;
26mod rb;
27mod rm;
28mod share;
29mod stat;
30mod tag;
31mod tree;
32mod version;
33
34#[derive(Parser, Debug)]
39#[command(name = "rc")]
40#[command(author, version, about, long_about = None)]
41#[command(propagate_version = true)]
42pub struct Cli {
43 #[arg(long, global = true, default_value = "false")]
45 pub json: bool,
46
47 #[arg(long, global = true, default_value = "false")]
49 pub no_color: bool,
50
51 #[arg(long, global = true, default_value = "false")]
53 pub no_progress: bool,
54
55 #[arg(short, long, global = true, default_value = "false")]
57 pub quiet: bool,
58
59 #[arg(long, global = true, default_value = "false")]
61 pub debug: bool,
62
63 #[command(subcommand)]
64 pub command: Commands,
65}
66
67#[derive(Subcommand, Debug)]
68pub enum Commands {
69 #[command(subcommand)]
71 Alias(alias::AliasCommands),
72
73 #[command(subcommand)]
75 Admin(admin::AdminCommands),
76
77 Ls(ls::LsArgs),
80
81 Mb(mb::MbArgs),
83
84 Rb(rb::RbArgs),
86
87 Cat(cat::CatArgs),
89
90 Head(head::HeadArgs),
92
93 Stat(stat::StatArgs),
95
96 Cp(cp::CpArgs),
99
100 Mv(mv::MvArgs),
102
103 Rm(rm::RmArgs),
105
106 Pipe(pipe::PipeArgs),
108
109 Find(find::FindArgs),
112
113 Diff(diff::DiffArgs),
115
116 Mirror(mirror::MirrorArgs),
118
119 Tree(tree::TreeArgs),
121
122 Share(share::ShareArgs),
124
125 #[command(subcommand)]
128 Version(version::VersionCommands),
129
130 #[command(subcommand)]
132 Tag(tag::TagCommands),
133
134 #[command(subcommand)]
136 Quota(quota::QuotaCommands),
137
138 Completions(completions::CompletionsArgs),
141 }
148
149pub async fn execute(cli: Cli) -> ExitCode {
151 let output_config = OutputConfig {
152 json: cli.json,
153 no_color: cli.no_color,
154 no_progress: cli.no_progress,
155 quiet: cli.quiet,
156 };
157
158 match cli.command {
159 Commands::Alias(cmd) => alias::execute(cmd, output_config).await,
160 Commands::Admin(cmd) => admin::execute(cmd, output_config).await,
161 Commands::Ls(args) => ls::execute(args, output_config).await,
162 Commands::Mb(args) => mb::execute(args, output_config).await,
163 Commands::Rb(args) => rb::execute(args, output_config).await,
164 Commands::Cat(args) => cat::execute(args, output_config).await,
165 Commands::Head(args) => head::execute(args, output_config).await,
166 Commands::Stat(args) => stat::execute(args, output_config).await,
167 Commands::Cp(args) => cp::execute(args, output_config).await,
168 Commands::Mv(args) => mv::execute(args, output_config).await,
169 Commands::Rm(args) => rm::execute(args, output_config).await,
170 Commands::Pipe(args) => pipe::execute(args, output_config).await,
171 Commands::Find(args) => find::execute(args, output_config).await,
172 Commands::Diff(args) => diff::execute(args, output_config).await,
173 Commands::Mirror(args) => mirror::execute(args, output_config).await,
174 Commands::Tree(args) => tree::execute(args, output_config).await,
175 Commands::Share(args) => share::execute(args, output_config).await,
176 Commands::Version(cmd) => {
177 version::execute(version::VersionArgs { command: cmd }, output_config).await
178 }
179 Commands::Tag(cmd) => tag::execute(tag::TagArgs { command: cmd }, output_config).await,
180 Commands::Quota(cmd) => {
181 quota::execute(quota::QuotaArgs { command: cmd }, output_config).await
182 }
183 Commands::Completions(args) => completions::execute(args),
184 }
185}