Skip to main content

rustfs_cli/commands/
mod.rs

1//! CLI command definitions and execution
2//!
3//! This module contains all CLI commands and their implementations.
4//! Commands are organized by functionality and follow the pattern established
5//! in the command implementation template.
6
7use clap::{Parser, Subcommand};
8
9use crate::exit_code::ExitCode;
10use crate::output::OutputConfig;
11
12mod admin;
13mod alias;
14mod anonymous;
15mod cat;
16mod completions;
17pub mod cp;
18pub mod diff;
19mod event;
20mod find;
21mod head;
22mod ilm;
23mod ls;
24mod mb;
25mod mirror;
26mod mv;
27mod pipe;
28mod quota;
29mod rb;
30mod replicate;
31mod rm;
32mod share;
33mod stat;
34mod tag;
35mod tree;
36mod version;
37
38/// rc - Rust S3 CLI Client
39///
40/// A command-line interface for S3-compatible object storage services.
41/// Supports RustFS, AWS S3, and other S3-compatible backends.
42#[derive(Parser, Debug)]
43#[command(name = "rc")]
44#[command(author, version, about, long_about = None)]
45#[command(propagate_version = true)]
46pub struct Cli {
47    /// Output format: human-readable or JSON
48    #[arg(long, global = true, default_value = "false")]
49    pub json: bool,
50
51    /// Disable colored output
52    #[arg(long, global = true, default_value = "false")]
53    pub no_color: bool,
54
55    /// Disable progress bar
56    #[arg(long, global = true, default_value = "false")]
57    pub no_progress: bool,
58
59    /// Suppress non-error output
60    #[arg(short, long, global = true, default_value = "false")]
61    pub quiet: bool,
62
63    /// Enable debug logging
64    #[arg(long, global = true, default_value = "false")]
65    pub debug: bool,
66
67    #[command(subcommand)]
68    pub command: Commands,
69}
70
71#[derive(Subcommand, Debug)]
72pub enum Commands {
73    /// Manage storage service aliases
74    #[command(subcommand)]
75    Alias(alias::AliasCommands),
76
77    /// Manage IAM users, policies, groups, and service accounts
78    #[command(subcommand)]
79    Admin(admin::AdminCommands),
80
81    // Phase 2: Basic commands
82    /// List buckets and objects
83    Ls(ls::LsArgs),
84
85    /// Create a bucket
86    Mb(mb::MbArgs),
87
88    /// Remove a bucket
89    Rb(rb::RbArgs),
90
91    /// Display object contents
92    Cat(cat::CatArgs),
93
94    /// Display first N lines of an object
95    Head(head::HeadArgs),
96
97    /// Show object metadata
98    Stat(stat::StatArgs),
99
100    // Phase 3: Transfer commands
101    /// Copy objects (local<->S3, S3<->S3)
102    Cp(cp::CpArgs),
103
104    /// Move objects (copy + delete source)
105    Mv(mv::MvArgs),
106
107    /// Remove objects
108    Rm(rm::RmArgs),
109
110    /// Stream stdin to an object
111    Pipe(pipe::PipeArgs),
112
113    // Phase 4: Advanced commands
114    /// Find objects matching criteria
115    Find(find::FindArgs),
116
117    /// Manage bucket event notifications
118    #[command(subcommand)]
119    Event(event::EventCommands),
120
121    /// Show differences between locations
122    Diff(diff::DiffArgs),
123
124    /// Mirror objects between locations
125    Mirror(mirror::MirrorArgs),
126
127    /// Display objects in tree format
128    Tree(tree::TreeArgs),
129
130    /// Generate presigned URLs
131    Share(share::ShareArgs),
132
133    // Phase 5: Optional commands (capability-dependent)
134    /// Manage bucket versioning
135    #[command(subcommand)]
136    Version(version::VersionCommands),
137
138    /// Manage bucket and object tags
139    #[command(subcommand)]
140    Tag(tag::TagCommands),
141
142    /// Manage anonymous access to buckets and objects
143    #[command(subcommand)]
144    Anonymous(anonymous::AnonymousCommands),
145
146    /// Manage bucket quota
147    #[command(subcommand)]
148    Quota(quota::QuotaCommands),
149
150    /// Manage bucket lifecycle (ILM) rules, tiers, and restores
151    Ilm(ilm::IlmArgs),
152
153    /// Manage bucket replication
154    #[command(subcommand)]
155    Replicate(replicate::ReplicateCommands),
156
157    // Phase 6: Utilities
158    /// Generate shell completion scripts
159    Completions(completions::CompletionsArgs),
160    // /// Manage object retention
161    // Retention(retention::RetentionArgs),
162    // /// Watch for object events
163    // Watch(watch::WatchArgs),
164    // /// Run S3 Select queries
165    // Sql(sql::SqlArgs),
166}
167
168/// Execute the CLI command and return an exit code
169pub async fn execute(cli: Cli) -> ExitCode {
170    let output_config = OutputConfig {
171        json: cli.json,
172        no_color: cli.no_color,
173        no_progress: cli.no_progress,
174        quiet: cli.quiet,
175    };
176
177    match cli.command {
178        Commands::Alias(cmd) => alias::execute(cmd, output_config).await,
179        Commands::Admin(cmd) => admin::execute(cmd, output_config).await,
180        Commands::Ls(args) => ls::execute(args, output_config).await,
181        Commands::Mb(args) => mb::execute(args, output_config).await,
182        Commands::Rb(args) => rb::execute(args, output_config).await,
183        Commands::Cat(args) => cat::execute(args, output_config).await,
184        Commands::Head(args) => head::execute(args, output_config).await,
185        Commands::Stat(args) => stat::execute(args, output_config).await,
186        Commands::Cp(args) => cp::execute(args, output_config).await,
187        Commands::Mv(args) => mv::execute(args, output_config).await,
188        Commands::Rm(args) => rm::execute(args, output_config).await,
189        Commands::Pipe(args) => pipe::execute(args, output_config).await,
190        Commands::Find(args) => find::execute(args, output_config).await,
191        Commands::Event(cmd) => {
192            event::execute(event::EventArgs { command: cmd }, output_config).await
193        }
194        Commands::Diff(args) => diff::execute(args, output_config).await,
195        Commands::Mirror(args) => mirror::execute(args, output_config).await,
196        Commands::Tree(args) => tree::execute(args, output_config).await,
197        Commands::Share(args) => share::execute(args, output_config).await,
198        Commands::Version(cmd) => {
199            version::execute(version::VersionArgs { command: cmd }, output_config).await
200        }
201        Commands::Tag(cmd) => tag::execute(tag::TagArgs { command: cmd }, output_config).await,
202        Commands::Anonymous(cmd) => {
203            anonymous::execute(anonymous::AnonymousArgs { command: cmd }, output_config).await
204        }
205        Commands::Quota(cmd) => {
206            quota::execute(quota::QuotaArgs { command: cmd }, output_config).await
207        }
208        Commands::Ilm(args) => ilm::execute(args, output_config).await,
209        Commands::Replicate(cmd) => {
210            replicate::execute(replicate::ReplicateArgs { command: cmd }, output_config).await
211        }
212        Commands::Completions(args) => completions::execute(args),
213    }
214}