-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathresult.rs
More file actions
65 lines (50 loc) · 1.61 KB
/
result.rs
File metadata and controls
65 lines (50 loc) · 1.61 KB
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
use stackable_cockpit::constants::{DEFAULT_NAMESPACE, DEFAULT_OPERATOR_NAMESPACE};
use crate::output::{ContextExt, OutputKind};
#[derive(Debug, Default)]
pub struct ResultContext {
used_operator_namespace: String,
used_namespace: String,
command_hints: Vec<String>,
post_hints: Vec<String>,
pre_hints: Vec<String>,
output: String,
no_color: bool,
}
impl ContextExt for ResultContext {
fn into_context(self) -> tera::Context {
let mut ctx = tera::Context::new();
ctx.insert("default_operator_namespace", DEFAULT_OPERATOR_NAMESPACE);
ctx.insert("default_namespace", DEFAULT_NAMESPACE);
ctx.insert("used_operator_namespace", &self.used_operator_namespace);
ctx.insert("used_namespace", &self.used_namespace);
ctx.insert("command_hints", &self.command_hints);
ctx.insert("post_hints", &self.post_hints);
ctx.insert("pre_hints", &self.pre_hints);
ctx.insert("output", &self.output);
ctx
}
fn output_kind(&self) -> OutputKind {
OutputKind::Result
}
fn set_no_color(&mut self, no_color: bool) {
self.no_color = no_color
}
}
impl ResultContext {
pub fn with_output(&mut self, output: impl Into<String>) -> &mut Self {
self.output = output.into();
self
}
pub fn with_command_hint(
&mut self,
command: impl Into<String>,
description: impl Into<String>,
) -> &mut Self {
self.command_hints.push(format!(
"Use \"{}\" to {}.",
command.into(),
description.into()
));
self
}
}