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 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/// rc - Rust S3 CLI Client
35///
36/// A command-line interface for S3-compatible object storage services.
37/// Supports RustFS, AWS S3, and other S3-compatible backends.
38#[derive(Parser, Debug)]
39#[command(name = "rc")]
40#[command(author, version, about, long_about = None)]
41#[command(propagate_version = true)]
42pub struct Cli {
43    /// Output format: human-readable or JSON
44    #[arg(long, global = true, default_value = "false")]
45    pub json: bool,
46
47    /// Disable colored output
48    #[arg(long, global = true, default_value = "false")]
49    pub no_color: bool,
50
51    /// Disable progress bar
52    #[arg(long, global = true, default_value = "false")]
53    pub no_progress: bool,
54
55    /// Suppress non-error output
56    #[arg(short, long, global = true, default_value = "false")]
57    pub quiet: bool,
58
59    /// Enable debug logging
60    #[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    /// Manage storage service aliases
70    #[command(subcommand)]
71    Alias(alias::AliasCommands),
72
73    /// Manage IAM users, policies, groups, and service accounts
74    #[command(subcommand)]
75    Admin(admin::AdminCommands),
76
77    // Phase 2: Basic commands
78    /// List buckets and objects
79    Ls(ls::LsArgs),
80
81    /// Create a bucket
82    Mb(mb::MbArgs),
83
84    /// Remove a bucket
85    Rb(rb::RbArgs),
86
87    /// Display object contents
88    Cat(cat::CatArgs),
89
90    /// Display first N lines of an object
91    Head(head::HeadArgs),
92
93    /// Show object metadata
94    Stat(stat::StatArgs),
95
96    // Phase 3: Transfer commands
97    /// Copy objects (local<->S3, S3<->S3)
98    Cp(cp::CpArgs),
99
100    /// Move objects (copy + delete source)
101    Mv(mv::MvArgs),
102
103    /// Remove objects
104    Rm(rm::RmArgs),
105
106    /// Stream stdin to an object
107    Pipe(pipe::PipeArgs),
108
109    // Phase 4: Advanced commands
110    /// Find objects matching criteria
111    Find(find::FindArgs),
112
113    /// Show differences between locations
114    Diff(diff::DiffArgs),
115
116    /// Mirror objects between locations
117    Mirror(mirror::MirrorArgs),
118
119    /// Display objects in tree format
120    Tree(tree::TreeArgs),
121
122    /// Generate presigned URLs
123    Share(share::ShareArgs),
124
125    // Phase 5: Optional commands (capability-dependent)
126    /// Manage bucket versioning
127    #[command(subcommand)]
128    Version(version::VersionCommands),
129
130    /// Manage bucket and object tags
131    #[command(subcommand)]
132    Tag(tag::TagCommands),
133
134    /// Manage bucket quota
135    #[command(subcommand)]
136    Quota(quota::QuotaCommands),
137
138    // Phase 6: Utilities
139    /// Generate shell completion scripts
140    Completions(completions::CompletionsArgs),
141    // /// Manage object retention
142    // Retention(retention::RetentionArgs),
143    // /// Watch for object events
144    // Watch(watch::WatchArgs),
145    // /// Run S3 Select queries
146    // Sql(sql::SqlArgs),
147}
148
149/// Execute the CLI command and return an exit code
150pub 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}