apcore_toolkit/output/
mod.rs1pub mod errors;
6pub mod registry_writer;
7pub mod types;
8pub mod verifiers;
9pub mod yaml_writer;
10
11#[cfg(feature = "http-proxy")]
12pub mod http_proxy_writer;
13
14use serde::{Deserialize, Serialize};
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
22pub enum OutputFormat {
23 Yaml,
25 Registry,
27 HttpProxy,
29}
30
31pub fn get_writer(format: &str) -> Option<OutputFormat> {
61 match format.to_ascii_lowercase().as_str() {
62 "yaml" => Some(OutputFormat::Yaml),
63 "registry" => Some(OutputFormat::Registry),
64 "http_proxy" | "http-proxy" | "httpproxy" => Some(OutputFormat::HttpProxy),
65 _ => None,
66 }
67}
68
69#[cfg(test)]
70mod tests {
71 use super::*;
72
73 #[test]
74 fn test_get_writer_yaml() {
75 assert_eq!(get_writer("yaml"), Some(OutputFormat::Yaml));
76 }
77
78 #[test]
79 fn test_get_writer_registry() {
80 assert_eq!(get_writer("registry"), Some(OutputFormat::Registry));
81 }
82
83 #[test]
84 fn test_get_writer_http_proxy_variants() {
85 assert_eq!(get_writer("http_proxy"), Some(OutputFormat::HttpProxy));
86 assert_eq!(get_writer("http-proxy"), Some(OutputFormat::HttpProxy));
87 assert_eq!(get_writer("httpproxy"), Some(OutputFormat::HttpProxy));
88 }
89
90 #[test]
91 fn test_get_writer_case_insensitive() {
92 assert_eq!(get_writer("YAML"), Some(OutputFormat::Yaml));
93 assert_eq!(get_writer("Registry"), Some(OutputFormat::Registry));
94 assert_eq!(get_writer("HTTP_PROXY"), Some(OutputFormat::HttpProxy));
95 }
96
97 #[test]
98 fn test_get_writer_unknown() {
99 assert_eq!(get_writer("xml"), None);
100 assert_eq!(get_writer(""), None);
101 }
102
103 #[test]
104 fn test_output_format_serde_roundtrip() {
105 let fmt = OutputFormat::Yaml;
106 let json = serde_json::to_string(&fmt).unwrap();
107 let deserialized: OutputFormat = serde_json::from_str(&json).unwrap();
108 assert_eq!(deserialized, fmt);
109 }
110}