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