systemprompt_models/profile/
runtime.rs1use serde::{Deserialize, Serialize};
4use std::fmt;
5
6#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
7pub struct RuntimeConfig {
8 #[serde(default)]
9 pub environment: Environment,
10
11 #[serde(default)]
12 pub log_level: LogLevel,
13
14 #[serde(default)]
15 pub output_format: OutputFormat,
16
17 #[serde(default)]
18 pub no_color: bool,
19
20 #[serde(default)]
21 pub non_interactive: bool,
22}
23
24impl Default for RuntimeConfig {
25 fn default() -> Self {
26 Self {
27 environment: Environment::Development,
28 log_level: LogLevel::Normal,
29 output_format: OutputFormat::Text,
30 no_color: false,
31 non_interactive: false,
32 }
33 }
34}
35
36#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
37#[serde(rename_all = "lowercase")]
38pub enum Environment {
39 #[default]
40 Development,
41 Test,
42 Staging,
43 Production,
44}
45
46impl Environment {
47 pub const fn is_development(&self) -> bool {
48 matches!(self, Self::Development)
49 }
50
51 pub const fn is_production(&self) -> bool {
52 matches!(self, Self::Production)
53 }
54
55 pub const fn is_test(&self) -> bool {
56 matches!(self, Self::Test)
57 }
58}
59
60impl fmt::Display for Environment {
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 match self {
63 Self::Development => write!(f, "development"),
64 Self::Test => write!(f, "test"),
65 Self::Staging => write!(f, "staging"),
66 Self::Production => write!(f, "production"),
67 }
68 }
69}
70
71impl std::str::FromStr for Environment {
72 type Err = String;
73
74 fn from_str(s: &str) -> Result<Self, Self::Err> {
75 match s.to_lowercase().as_str() {
76 "development" => Ok(Self::Development),
77 "test" => Ok(Self::Test),
78 "staging" => Ok(Self::Staging),
79 "production" => Ok(Self::Production),
80 _ => Err(format!(
81 "Invalid environment '{}'. Must be one of: development, test, staging, production",
82 s
83 )),
84 }
85 }
86}
87
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
89#[serde(rename_all = "lowercase")]
90pub enum LogLevel {
91 Quiet,
92 #[default]
93 Normal,
94 Verbose,
95 Debug,
96}
97
98impl LogLevel {
99 pub const fn as_tracing_filter(&self) -> &'static str {
100 match self {
101 Self::Quiet => "error",
102 Self::Normal => "info",
103 Self::Verbose => "debug",
104 Self::Debug => "trace",
105 }
106 }
107}
108
109impl fmt::Display for LogLevel {
110 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
111 match self {
112 Self::Quiet => write!(f, "quiet"),
113 Self::Normal => write!(f, "normal"),
114 Self::Verbose => write!(f, "verbose"),
115 Self::Debug => write!(f, "debug"),
116 }
117 }
118}
119
120impl std::str::FromStr for LogLevel {
121 type Err = String;
122
123 fn from_str(s: &str) -> Result<Self, Self::Err> {
124 match s.to_lowercase().as_str() {
125 "quiet" => Ok(Self::Quiet),
126 "normal" => Ok(Self::Normal),
127 "verbose" => Ok(Self::Verbose),
128 "debug" => Ok(Self::Debug),
129 _ => Err(format!(
130 "Invalid log level '{}'. Must be one of: quiet, normal, verbose, debug",
131 s
132 )),
133 }
134 }
135}
136
137#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
138#[serde(rename_all = "lowercase")]
139pub enum OutputFormat {
140 #[default]
141 Text,
142 Json,
143 Yaml,
144}
145
146impl fmt::Display for OutputFormat {
147 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
148 match self {
149 Self::Text => write!(f, "text"),
150 Self::Json => write!(f, "json"),
151 Self::Yaml => write!(f, "yaml"),
152 }
153 }
154}
155
156impl std::str::FromStr for OutputFormat {
157 type Err = String;
158
159 fn from_str(s: &str) -> Result<Self, Self::Err> {
160 match s.to_lowercase().as_str() {
161 "text" => Ok(Self::Text),
162 "json" => Ok(Self::Json),
163 "yaml" => Ok(Self::Yaml),
164 _ => Err(format!(
165 "Invalid output format '{}'. Must be one of: text, json, yaml",
166 s
167 )),
168 }
169 }
170}