1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
/// Program stdout settings
#[derive(Debug, Clone)]
pub struct ProgramStdoutSetting {
/// Output error messages
pub error_output: bool,
/// Render results and output
pub render_output: bool,
/// Silence panic messages
pub silence_panic: bool,
/// Verbose output: provide detailed information
///
/// **NOTE**: Convention only, not a configuration
pub verbose: bool,
/// Quiet mode: suppress status messages, show only errors and results
///
/// **NOTE**: Convention only, not a configuration
pub quiet: bool,
/// Debug mode: output internal state and detailed diagnostics
///
/// **NOTE**: Convention only, not a configuration
pub debug: bool,
/// Enable colored output
///
/// **NOTE**: Convention only, not a configuration
pub color: bool,
/// Show progress indicators (e.g. progress bars, spinners)
///
/// Automatically disabled when stdout is not a tty.
///
/// **NOTE**: Convention only, not a configuration
pub progress: bool,
#[cfg(feature = "clap")]
/// Behavior when Clap Dispatcher outputs help information
pub clap_help_print_behaviour: ClapHelpPrintBehaviour,
}
#[cfg(feature = "clap")]
#[derive(Debug, Default, Clone)]
pub enum ClapHelpPrintBehaviour {
/// Write to RenderResult
WriteToRenderResult,
/// Print directly
#[default]
PrintDirectly,
}
impl Default for ProgramStdoutSetting {
fn default() -> Self {
ProgramStdoutSetting {
error_output: true,
render_output: true,
silence_panic: false,
verbose: false,
quiet: false,
debug: false,
color: true,
progress: true,
#[cfg(feature = "clap")]
clap_help_print_behaviour: ClapHelpPrintBehaviour::default(),
}
}
}
/// Program user context
#[derive(Debug, Clone)]
pub struct ProgramUserContext {
/// View help information instead of running the command
pub help: bool,
/// Execute hooks during the program lifecycle
pub run_hook: bool,
/// Skip user confirmation step
///
/// **NOTE**: Convention only, not a configuration
pub confirm: bool,
/// Dry-run mode: simulate actions without making changes
///
/// **NOTE**: Convention only, not a configuration
pub dry_run: bool,
/// Force execution, skipping safety checks
///
/// **NOTE**: Convention only, not a configuration
pub force: bool,
/// Whether the program is running in an interactive terminal (has a tty)
///
/// **NOTE**: Convention only, not a configuration
pub interactive: bool,
/// Assume "yes" for all confirmation prompts
///
/// **NOTE**: Convention only, not a configuration
pub assume_yes: bool,
}
impl Default for ProgramUserContext {
fn default() -> Self {
Self {
help: false,
run_hook: true,
confirm: false,
dry_run: false,
force: false,
interactive: false,
assume_yes: false,
}
}
}
#[cfg(feature = "general_renderer")]
#[derive(Debug, Clone, Default)]
/// Settings for the general renderer output format.
///
/// Controls how structured data (e.g., JSON, YAML, TOML) is rendered to stdout.
pub enum GeneralRendererSetting {
/// Do not render structured output (use default formatting).
#[default]
Disable,
/// Render output as compact JSON.
#[cfg(feature = "json_serde_fmt")]
Json,
/// Render output as pretty-printed JSON.
#[cfg(feature = "json_serde_fmt")]
JsonPretty,
/// Render output as YAML.
#[cfg(feature = "yaml_serde_fmt")]
Yaml,
/// Render output as TOML.
#[cfg(feature = "toml_serde_fmt")]
Toml,
/// Render output as RON.
#[cfg(feature = "ron_serde_fmt")]
Ron,
/// Render output as pretty-printed RON.
#[cfg(feature = "ron_serde_fmt")]
RonPretty,
}
#[cfg(feature = "general_renderer")]
impl std::str::FromStr for GeneralRendererSetting {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match just_fmt::kebab_case!(s).as_str() {
"disable" => Ok(GeneralRendererSetting::Disable),
#[cfg(feature = "json_serde_fmt")]
"json" => Ok(GeneralRendererSetting::Json),
#[cfg(feature = "json_serde_fmt")]
"json-pretty" => Ok(GeneralRendererSetting::JsonPretty),
#[cfg(feature = "yaml_serde_fmt")]
"yaml" => Ok(GeneralRendererSetting::Yaml),
#[cfg(feature = "toml_serde_fmt")]
"toml" => Ok(GeneralRendererSetting::Toml),
#[cfg(feature = "ron_serde_fmt")]
"ron" => Ok(GeneralRendererSetting::Ron),
#[cfg(feature = "ron_serde_fmt")]
"ron-pretty" => Ok(GeneralRendererSetting::RonPretty),
_ => Err(format!("Invalid renderer: '{s}'")),
}
}
}
#[cfg(feature = "general_renderer")]
impl From<&str> for GeneralRendererSetting {
fn from(s: &str) -> Self {
s.parse().unwrap_or(GeneralRendererSetting::Disable)
}
}
#[cfg(feature = "general_renderer")]
impl From<String> for GeneralRendererSetting {
fn from(s: String) -> Self {
s.as_str().into()
}
}
#[cfg(feature = "general_renderer")]
impl std::fmt::Display for GeneralRendererSetting {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
GeneralRendererSetting::Disable => write!(f, "disable"),
#[cfg(feature = "json_serde_fmt")]
GeneralRendererSetting::Json => write!(f, "json"),
#[cfg(feature = "json_serde_fmt")]
GeneralRendererSetting::JsonPretty => write!(f, "json-pretty"),
#[cfg(feature = "yaml_serde_fmt")]
GeneralRendererSetting::Yaml => write!(f, "yaml"),
#[cfg(feature = "toml_serde_fmt")]
GeneralRendererSetting::Toml => write!(f, "toml"),
#[cfg(feature = "ron_serde_fmt")]
GeneralRendererSetting::Ron => write!(f, "ron"),
#[cfg(feature = "ron_serde_fmt")]
GeneralRendererSetting::RonPretty => write!(f, "ron-pretty"),
}
}
}
|