Skip to main content

verbs/
completion_plan.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Pure shell-completion validation (no clap / script I/O / recovery copy).
3//!
4//! Core owns shell name parsing and a typed error. Presentation
5//! (`RecoveryAdvice` kind/summary/hint/example) is CLI-owned.
6
7/// Shells that Heddle emits completion scripts for.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum CompletionShell {
10    Bash,
11    Zsh,
12    Fish,
13}
14
15/// Failure to parse a completion shell name.
16#[derive(Debug, Clone, PartialEq, Eq)]
17pub enum CompletionShellError {
18    /// Token is not one of `bash` / `zsh` / `fish`.
19    Unsupported { shell: String },
20}
21
22/// Parse a user-supplied shell name into a known completion target.
23///
24/// Accepts only the exact lowercase tokens `bash`, `zsh`, and `fish`.
25pub fn parse_completion_shell(s: &str) -> Result<CompletionShell, CompletionShellError> {
26    match s {
27        "bash" => Ok(CompletionShell::Bash),
28        "zsh" => Ok(CompletionShell::Zsh),
29        "fish" => Ok(CompletionShell::Fish),
30        other => Err(CompletionShellError::Unsupported {
31            shell: other.to_string(),
32        }),
33    }
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn parse_known_shells() {
42        assert_eq!(parse_completion_shell("bash"), Ok(CompletionShell::Bash));
43        assert_eq!(parse_completion_shell("zsh"), Ok(CompletionShell::Zsh));
44        assert_eq!(parse_completion_shell("fish"), Ok(CompletionShell::Fish));
45        assert!(matches!(
46            parse_completion_shell("BASH"),
47            Err(CompletionShellError::Unsupported { .. })
48        ));
49        assert!(matches!(
50            parse_completion_shell("powershell"),
51            Err(CompletionShellError::Unsupported { shell }) if shell == "powershell"
52        ));
53    }
54}