diff options
| author | salmonik <raisersoft@proton.me> | 2026-05-13 11:27:16 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-05-13 11:27:16 +0200 |
| commit | 1059d878476c231f84ef9d3c2e8bcafaf978bc87 (patch) | |
| tree | 91a5ac153299764efcb8cf439ca7751152a34274 /src | |
| parent | Add display_format config, fix restart command, clean up config code (diff) | |
| download | rsplayer-1059d878476c231f84ef9d3c2e8bcafaf978bc87.tar.gz rsplayer-1059d878476c231f84ef9d3c2e8bcafaf978bc87.zip | |
Regenerate shell completions and install script fixes
- Add hidden completions subcommand to CLI (developer use only)
- Regenerate all completion scripts from current CLI structure
- Add elvish and powershell completion scripts
- install.sh: Fix rsp stop -> rsp stop-daemon, rsp start -> rsp start-daemon
- install.sh: Install completions for user's current shell
- install.sh: Zsh uses /usr/share/zsh/site-functions/_rsp directly
Diffstat (limited to '')
| -rw-r--r-- | src/cli.rs | 43 |
1 files changed, 42 insertions, 1 deletions
| @@ -1,6 +1,7 @@ | |||
| 1 | use crate::config::Config; | 1 | use crate::config::Config; |
| 2 | use crate::database::Database; | 2 | use crate::database::Database; |
| 3 | use clap::{Parser, Subcommand}; | 3 | use clap::{CommandFactory, Parser, Subcommand}; |
| 4 | use clap_complete::{Shell, generate}; | ||
| 4 | use std::path::PathBuf; | 5 | use std::path::PathBuf; |
| 5 | 6 | ||
| 6 | #[derive(Parser)] | 7 | #[derive(Parser)] |
| @@ -73,6 +74,14 @@ pub enum Commands { | |||
| 73 | #[command(subcommand)] | 74 | #[command(subcommand)] |
| 74 | command: SettingsCommands, | 75 | command: SettingsCommands, |
| 75 | }, | 76 | }, |
| 77 | #[clap(hide = true)] | ||
| 78 | /// Generate shell completions (developer only) | ||
| 79 | Completions { | ||
| 80 | /// Shell to generate (bash, zsh, fish, elvish, powershell) | ||
| 81 | /// If not specified, generates all completion files | ||
| 82 | #[arg(value_name = "SHELL")] | ||
| 83 | shell: Option<String>, | ||
| 84 | }, | ||
| 76 | } | 85 | } |
| 77 | 86 | ||
| 78 | #[derive(Subcommand)] | 87 | #[derive(Subcommand)] |
| @@ -200,6 +209,38 @@ impl Cli { | |||
| 200 | } | 209 | } |
| 201 | } | 210 | } |
| 202 | } | 211 | } |
| 212 | Commands::Completions { shell } => { | ||
| 213 | let mut cmd = Cli::command(); | ||
| 214 | if let Some(s) = shell { | ||
| 215 | let shell = match s.as_str() { | ||
| 216 | "bash" => Shell::Bash, | ||
| 217 | "zsh" => Shell::Zsh, | ||
| 218 | "fish" => Shell::Fish, | ||
| 219 | "elvish" => Shell::Elvish, | ||
| 220 | "powershell" => Shell::PowerShell, | ||
| 221 | _ => { | ||
| 222 | eprintln!("Unknown shell: {s}"); | ||
| 223 | return Ok(()); | ||
| 224 | } | ||
| 225 | }; | ||
| 226 | generate(shell, &mut cmd, "rsp", &mut std::io::stdout()); | ||
| 227 | } else { | ||
| 228 | std::fs::create_dir_all("completions/")?; | ||
| 229 | let shells = [ | ||
| 230 | (Shell::Bash, "bash"), | ||
| 231 | (Shell::Zsh, "zsh"), | ||
| 232 | (Shell::Fish, "fish"), | ||
| 233 | (Shell::Elvish, "elvish"), | ||
| 234 | (Shell::PowerShell, "powershell"), | ||
| 235 | ]; | ||
| 236 | for (shell, ext) in &shells { | ||
| 237 | let path = format!("completions/rsp.{ext}"); | ||
| 238 | let mut file = std::fs::File::create(&path)?; | ||
| 239 | generate(*shell, &mut cmd, "rsp", &mut file); | ||
| 240 | println!("Generated {path}"); | ||
| 241 | } | ||
| 242 | } | ||
| 243 | } | ||
| 203 | } | 244 | } |
| 204 | Ok(()) | 245 | Ok(()) |
| 205 | } | 246 | } |
