subx_cli/cli/generate_completion_args.rs
1//! Shell completion script generation command-line arguments.
2//!
3//! This module defines the command-line interface for generating shell completion
4//! scripts that enable tab completion for SubX commands in various shell environments.
5//! This significantly improves the user experience by providing intelligent command
6//! and argument completion.
7//!
8//! # Supported Shells
9//!
10//! SubX can generate completion scripts for all major shells:
11//! - **Bash**: Most common on Linux systems
12//! - **Zsh**: Default on macOS and advanced Linux setups
13//! - **Fish**: Modern shell with powerful completion features
14//! - **PowerShell**: Windows and cross-platform PowerShell environments
15//! - **Elvish**: Modern shell with structured data support
16//!
17//! # Completion Features
18//!
19//! Generated completion scripts provide:
20//! - **Command Completion**: Tab completion for all subcommands
21//! - **Argument Completion**: Intelligent completion for command arguments
22//! - **Path Completion**: File and directory path suggestions
23//! - **Enum Completion**: Valid values for enum-based arguments
24//! - **Help Integration**: Context-aware help text display
25//!
26//! # Installation Examples
27//!
28//! ```bash
29//! # Bash (add to ~/.bashrc)
30//! eval "$(subx generate-completion bash)"
31//!
32//! # Zsh (add to ~/.zshrc)
33//! eval "$(subx generate-completion zsh)"
34//!
35//! # Fish (save to completions directory)
36//! subx generate-completion fish > ~/.config/fish/completions/subx.fish
37//!
38//! # PowerShell (add to profile)
39//! subx generate-completion powershell | Out-String | Invoke-Expression
40//! ```
41
42// src/cli/generate_completion_args.rs
43use clap::Args;
44use clap_complete::Shell;
45
46/// Command-line arguments for generating shell completion scripts.
47///
48/// The generate-completion command creates shell-specific completion scripts
49/// that enable intelligent tab completion for SubX commands and arguments.
50/// This greatly enhances the command-line user experience by providing
51/// context-aware suggestions and reducing typing requirements.
52///
53/// # Completion Capabilities
54///
55/// Generated scripts provide completion for:
56/// - **Subcommands**: `match`, `convert`, `sync`, `detect-encoding`, etc.
57/// - **Flags and Options**: `--format`, `--output`, `--confidence`, etc.
58/// - **Enum Values**: Available formats, AI providers, sync methods
59/// - **File Paths**: Intelligent file and directory completion
60/// - **Configuration Keys**: Valid configuration setting names
61///
62/// # Shell Integration
63///
64/// Each shell has different integration methods:
65/// - **Immediate**: Load completion in current session
66/// - **Persistent**: Add to shell configuration for permanent availability
67/// - **System-wide**: Install for all users on the system
68/// - **Per-project**: Enable completion in specific project directories
69///
70/// # Performance Considerations
71///
72/// Completion scripts are optimized for performance:
73/// - **Lazy Loading**: Completions are generated on-demand
74/// - **Caching**: Results are cached where appropriate
75/// - **Minimal Overhead**: Scripts add minimal startup time to shell
76/// - **Incremental Updates**: Only regenerate when command structure changes
77///
78/// # Examples
79///
80/// ```rust
81/// use subx_cli::cli::GenerateCompletionArgs;
82/// use clap_complete::Shell;
83///
84/// // Generate Bash completion
85/// let bash_args = GenerateCompletionArgs {
86/// shell: Shell::Bash,
87/// };
88///
89/// // Generate Zsh completion
90/// let zsh_args = GenerateCompletionArgs {
91/// shell: Shell::Zsh,
92/// };
93///
94/// // Generate Fish completion
95/// let fish_args = GenerateCompletionArgs {
96/// shell: Shell::Fish,
97/// };
98/// ```
99#[derive(Args, Debug)]
100pub struct GenerateCompletionArgs {
101 /// Target shell for completion script generation.
102 ///
103 /// Specifies which shell environment the completion script should target.
104 /// Each shell has different syntax and capabilities, so the generated
105 /// script is optimized for the specific shell's completion system.
106 ///
107 /// # Shell-Specific Features
108 ///
109 /// ## Bash
110 /// - Traditional completion with `complete` command
111 /// - Basic argument and flag completion
112 /// - Compatible with most Linux distributions
113 /// - Works with Bash 4.0+ (recommended: 4.4+)
114 ///
115 /// ## Zsh
116 /// - Advanced completion with `_arguments` function
117 /// - Rich help text and description display
118 /// - Smart caching and performance optimization
119 /// - Compatible with Oh My Zsh and other frameworks
120 ///
121 /// ## Fish
122 /// - Native completion with `complete` command
123 /// - Excellent help text integration
124 /// - Real-time completion suggestions
125 /// - Works with all Fish versions 3.0+
126 ///
127 /// ## PowerShell
128 /// - Register-ArgumentCompleter integration
129 /// - Full .NET completion capabilities
130 /// - Works on Windows, Linux, and macOS
131 /// - Compatible with PowerShell 5.1+ and PowerShell Core
132 ///
133 /// ## Elvish
134 /// - Modern completion with structured data
135 /// - Rich metadata and help integration
136 /// - Advanced completion customization
137 /// - Works with Elvish 0.18+
138 ///
139 /// # Installation Instructions
140 ///
141 /// ## Bash
142 /// ```bash
143 /// # Temporary (current session only)
144 /// eval "$(subx generate-completion bash)"
145 ///
146 /// # Permanent (add to ~/.bashrc)
147 /// echo 'eval "$(subx generate-completion bash)"' >> ~/.bashrc
148 ///
149 /// # System-wide (requires sudo)
150 /// subx generate-completion bash > /etc/bash_completion.d/subx
151 /// ```
152 ///
153 /// ## Zsh
154 /// ```bash
155 /// # Temporary (current session only)
156 /// eval "$(subx generate-completion zsh)"
157 ///
158 /// # Permanent (add to ~/.zshrc)
159 /// echo 'eval "$(subx generate-completion zsh)"' >> ~/.zshrc
160 ///
161 /// # Oh My Zsh (create plugin)
162 /// mkdir -p ~/.oh-my-zsh/custom/plugins/subx
163 /// subx generate-completion zsh > ~/.oh-my-zsh/custom/plugins/subx/_subx
164 /// ```
165 ///
166 /// ## Fish
167 /// ```bash
168 /// # Save to Fish completions directory
169 /// subx generate-completion fish > ~/.config/fish/completions/subx.fish
170 ///
171 /// # System-wide installation
172 /// sudo subx generate-completion fish > /usr/share/fish/completions/subx.fish
173 /// ```
174 ///
175 /// ## PowerShell
176 /// ```powershell
177 /// # Add to PowerShell profile
178 /// subx generate-completion powershell | Out-String | Invoke-Expression
179 ///
180 /// # Permanent installation (add to profile)
181 /// Add-Content $PROFILE "subx generate-completion powershell | Out-String | Invoke-Expression"
182 /// ```
183 ///
184 /// # Troubleshooting
185 ///
186 /// Common issues and solutions:
187 /// - **Completion not working**: Verify shell version compatibility
188 /// - **Slow completion**: Check for conflicting completion scripts
189 /// - **Missing commands**: Ensure SubX is in PATH
190 /// - **Permission errors**: Use appropriate installation method for your system
191 ///
192 /// # Examples
193 ///
194 /// ```bash
195 /// # Generate and view Bash completion
196 /// subx generate-completion bash
197 ///
198 /// # Generate and install Fish completion
199 /// subx generate-completion fish > ~/.config/fish/completions/subx.fish
200 ///
201 /// # Generate PowerShell completion and execute immediately
202 /// subx generate-completion powershell | Out-String | Invoke-Expression
203 /// ```
204 #[arg(value_enum)]
205 pub shell: Shell,
206}