use super::{OsFlavor, Shell, ShellContext, ShellType};
pub fn generate_powershell_content(zv_dir: &str, zv_bin_path: &str) -> String {
let shell = Shell {
shell_type: ShellType::PowerShell,
context: ShellContext {
target_os: if cfg!(target_os = "windows") {
OsFlavor::Windows
} else {
OsFlavor::Unix
},
is_wsl: false,
is_emulated: cfg!(unix), },
};
shell.generate_env_content(zv_dir, zv_bin_path, true)
}
pub fn generate_cmd_content(zv_dir: &str, zv_bin_path: &str) -> String {
let shell = Shell {
shell_type: ShellType::Cmd,
context: ShellContext {
target_os: OsFlavor::Windows,
is_wsl: false,
is_emulated: false,
},
};
shell.generate_env_content(zv_dir, zv_bin_path, true)
}
#[cfg(not(target_os = "linux"))]
pub fn generate_fish_content(zv_dir: &str, zv_bin_path: &str) -> String {
let shell = Shell {
shell_type: ShellType::Fish,
context: ShellContext {
target_os: if cfg!(target_os = "windows") {
OsFlavor::Windows
} else {
OsFlavor::Unix
},
is_wsl: false,
is_emulated: cfg!(target_os = "windows"), },
};
shell.generate_env_content(zv_dir, zv_bin_path, true)
}
#[cfg(not(target_os = "linux"))]
pub fn generate_nu_content(zv_dir: &str, zv_bin_path: &str) -> String {
let shell = Shell {
shell_type: ShellType::Nu,
context: ShellContext {
target_os: if cfg!(target_os = "windows") {
OsFlavor::Windows
} else {
OsFlavor::Unix
},
is_wsl: false,
is_emulated: cfg!(target_os = "windows"), },
};
shell.generate_env_content(zv_dir, zv_bin_path, true)
}
#[cfg(not(target_os = "linux"))]
pub fn generate_tcsh_content(zv_dir: &str, zv_bin_path: &str) -> String {
let shell = Shell {
shell_type: ShellType::Tcsh,
context: ShellContext {
target_os: if cfg!(target_os = "windows") {
OsFlavor::Windows
} else {
OsFlavor::Unix
},
is_wsl: false,
is_emulated: cfg!(target_os = "windows"), },
};
shell.generate_env_content(zv_dir, zv_bin_path, true)
}
#[cfg(not(target_os = "linux"))]
pub fn generate_posix_content(zv_dir: &str, zv_bin_path: &str) -> String {
let shell = Shell {
shell_type: ShellType::Bash,
context: ShellContext {
target_os: if cfg!(target_os = "windows") {
OsFlavor::Windows
} else {
OsFlavor::Unix
},
is_wsl: false,
is_emulated: cfg!(target_os = "windows"), },
};
shell.generate_env_content(zv_dir, zv_bin_path, true)
}
#[cfg(not(target_os = "linux"))]
pub fn generate_cleanup_content(shell: &Shell, zv_dir: &str, zv_bin_path: &str) -> String {
shell.generate_cleanup_content(zv_dir, zv_bin_path, true)
}
fn generate_powershell_cleanup(zv_dir: &str, zv_bin_path: &str) -> String {
let shell = Shell {
shell_type: ShellType::PowerShell,
context: ShellContext {
target_os: if cfg!(target_os = "windows") {
OsFlavor::Windows
} else {
OsFlavor::Unix
},
is_wsl: false,
is_emulated: cfg!(unix), },
};
shell.generate_cleanup_content(zv_dir, zv_bin_path, true)
}
fn generate_cmd_cleanup(zv_dir: &str, zv_bin_path: &str) -> String {
let shell = Shell {
shell_type: ShellType::Cmd,
context: ShellContext {
target_os: OsFlavor::Windows,
is_wsl: false,
is_emulated: false,
},
};
shell.generate_cleanup_content(zv_dir, zv_bin_path, true)
}
#[cfg(not(target_os = "linux"))]
fn generate_fish_cleanup(zv_dir: &str, zv_bin_path: &str) -> String {
let shell = Shell {
shell_type: ShellType::Fish,
context: ShellContext {
target_os: if cfg!(target_os = "windows") {
OsFlavor::Windows
} else {
OsFlavor::Unix
},
is_wsl: false,
is_emulated: cfg!(target_os = "windows"), },
};
shell.generate_cleanup_content(zv_dir, zv_bin_path, true)
}
#[cfg(not(target_os = "linux"))]
fn generate_nu_cleanup(zv_dir: &str, zv_bin_path: &str) -> String {
let shell = Shell {
shell_type: ShellType::Nu,
context: ShellContext {
target_os: if cfg!(target_os = "windows") {
OsFlavor::Windows
} else {
OsFlavor::Unix
},
is_wsl: false,
is_emulated: cfg!(target_os = "windows"), },
};
shell.generate_cleanup_content(zv_dir, zv_bin_path, true)
}
#[cfg(not(target_os = "linux"))]
fn generate_tcsh_cleanup(zv_dir: &str, zv_bin_path: &str) -> String {
let shell = Shell {
shell_type: ShellType::Tcsh,
context: ShellContext {
target_os: if cfg!(target_os = "windows") {
OsFlavor::Windows
} else {
OsFlavor::Unix
},
is_wsl: false,
is_emulated: cfg!(target_os = "windows"), },
};
shell.generate_cleanup_content(zv_dir, zv_bin_path, true)
}
#[cfg(not(target_os = "linux"))]
fn generate_posix_cleanup(zv_dir: &str, zv_bin_path: &str) -> String {
let shell = Shell {
shell_type: ShellType::Bash,
context: ShellContext {
target_os: if cfg!(target_os = "windows") {
OsFlavor::Windows
} else {
OsFlavor::Unix
},
is_wsl: false,
is_emulated: cfg!(target_os = "windows"), },
};
shell.generate_cleanup_content(zv_dir, zv_bin_path, true)
}
#[cfg(not(target_os = "linux"))]
pub fn generate_setup_instructions(shell: &Shell, env_file_path: &str) -> String {
shell.generate_setup_instructions(env_file_path)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_generate_powershell_content() {
let content = generate_powershell_content("C:\\zv", "C:\\zv\\bin");
assert!(content.contains("$env:ZV_DIR"));
assert!(content.contains("$env:PATH"));
assert!(content.contains("C:\\zv"));
assert!(content.contains("C:\\zv\\bin"));
}
#[cfg(not(target_os = "linux"))]
#[test]
fn test_generate_fish_content() {
let content = generate_fish_content("/home/user/.zv", "/home/user/.zv/bin");
assert!(content.contains("set -gx ZV_DIR"));
assert!(content.contains("set -gx PATH"));
assert!(content.contains("/home/user/.zv"));
}
#[cfg(not(target_os = "linux"))]
#[test]
fn test_generate_posix_content() {
let content = generate_posix_content("/home/user/.zv", "/home/user/.zv/bin");
assert!(content.contains("export ZV_DIR"));
assert!(content.contains("export PATH"));
assert!(content.contains("case"));
assert!(content.contains("/home/user/.zv"));
}
#[cfg(not(target_os = "linux"))]
#[test]
fn test_generate_cleanup_content() {
let shell = Shell {
shell_type: ShellType::Fish,
context: ShellContext {
target_os: OsFlavor::Unix,
is_wsl: false,
is_emulated: false,
},
};
let cleanup = generate_cleanup_content(&shell, "/home/user/.zv", "/home/user/.zv/bin");
assert!(cleanup.contains("set -e ZV_DIR"));
assert!(cleanup.contains("contains -i"));
}
#[cfg(not(target_os = "linux"))]
#[test]
fn test_generate_setup_instructions() {
let shell = Shell {
shell_type: ShellType::Bash,
context: ShellContext {
target_os: OsFlavor::Unix,
is_wsl: false,
is_emulated: false,
},
};
let instructions = generate_setup_instructions(&shell, "/home/user/.zv/env");
assert!(instructions.contains("source"));
assert!(instructions.contains("~/.bashrc"));
assert!(instructions.contains("/home/user/.zv/env"));
}
}