#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HookInstallSourceKind {
File,
Stdin,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HookInstallSourcePlan {
Proceed(HookInstallSourceKind),
SourceRequired,
EmptyStdin,
}
pub fn plan_hook_install_source(
from_file: bool,
from_stdin: bool,
stdin_empty: bool,
) -> HookInstallSourcePlan {
if from_file {
return HookInstallSourcePlan::Proceed(HookInstallSourceKind::File);
}
if from_stdin {
if stdin_empty {
return HookInstallSourcePlan::EmptyStdin;
}
return HookInstallSourcePlan::Proceed(HookInstallSourceKind::Stdin);
}
HookInstallSourcePlan::SourceRequired
}
pub fn hook_install_source_required_kind() -> &'static str {
"hook_install_source_required"
}
pub fn hook_install_empty_stdin_kind() -> &'static str {
"hook_install_empty_stdin"
}
pub fn hook_unknown_kind() -> &'static str {
"hook_unknown"
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn install_source_plans() {
assert_eq!(
plan_hook_install_source(true, false, true),
HookInstallSourcePlan::Proceed(HookInstallSourceKind::File)
);
assert_eq!(
plan_hook_install_source(false, true, false),
HookInstallSourcePlan::Proceed(HookInstallSourceKind::Stdin)
);
assert_eq!(
plan_hook_install_source(false, true, true),
HookInstallSourcePlan::EmptyStdin
);
assert_eq!(
plan_hook_install_source(false, false, false),
HookInstallSourcePlan::SourceRequired
);
}
}