1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum HookInstallSourceKind {
7 File,
8 Stdin,
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum HookInstallSourcePlan {
14 Proceed(HookInstallSourceKind),
16 SourceRequired,
18 EmptyStdin,
20}
21
22pub fn plan_hook_install_source(
28 from_file: bool,
29 from_stdin: bool,
30 stdin_empty: bool,
31) -> HookInstallSourcePlan {
32 if from_file {
33 return HookInstallSourcePlan::Proceed(HookInstallSourceKind::File);
34 }
35 if from_stdin {
36 if stdin_empty {
37 return HookInstallSourcePlan::EmptyStdin;
38 }
39 return HookInstallSourcePlan::Proceed(HookInstallSourceKind::Stdin);
40 }
41 HookInstallSourcePlan::SourceRequired
42}
43
44pub fn hook_install_source_required_kind() -> &'static str {
46 "hook_install_source_required"
47}
48
49pub fn hook_install_empty_stdin_kind() -> &'static str {
50 "hook_install_empty_stdin"
51}
52
53pub fn hook_unknown_kind() -> &'static str {
54 "hook_unknown"
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn install_source_plans() {
63 assert_eq!(
64 plan_hook_install_source(true, false, true),
65 HookInstallSourcePlan::Proceed(HookInstallSourceKind::File)
66 );
67 assert_eq!(
68 plan_hook_install_source(false, true, false),
69 HookInstallSourcePlan::Proceed(HookInstallSourceKind::Stdin)
70 );
71 assert_eq!(
72 plan_hook_install_source(false, true, true),
73 HookInstallSourcePlan::EmptyStdin
74 );
75 assert_eq!(
76 plan_hook_install_source(false, false, false),
77 HookInstallSourcePlan::SourceRequired
78 );
79 }
80}