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
// Copyright 2021 Databricks, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use clap::{Arg, Command as ClapCommand};
use rustyline::completion::Pair as RustlinePair;
use crate::{
command::command_def::{exec_match, start_clap, Cmd},
completer,
env::Env,
output::ClickWriter,
};
use std::cell::RefCell;
use std::collections::HashMap;
use std::io::Write;
use super::events::print_events_for_obj;
command!(
Describe,
"describe",
"Describe the active kubernetes object.",
|clap: ClapCommand<'static>| {
clap.arg(
Arg::new("json")
.short('j')
.long("json")
.help("Print the full description in json")
.takes_value(false),
)
.arg(
Arg::new("yaml")
.short('y')
.long("yaml")
.help("Print the full description in yaml")
.takes_value(false),
)
.arg(
Arg::new("include_events")
.short('e')
.long("events")
.help(
"If true, include events in the output, if false, do not. \
Default can be set by 'set describe_include_events [true/false]'",
)
.takes_value(true)
.value_parser(["true", "false"]),
)
},
vec!["describe"],
noop_complete!(),
no_named_complete!(),
|matches, env, writer| {
let mut include_events = env.click_config.describe_include_events;
if let Some(b) = matches
.get_one::<String>("include_events")
.map(|s| s.as_str())
{
include_events = b.parse().unwrap(); // safe, validated to be true/false
}
env.apply_to_selection(
writer,
Some(&env.click_config.range_separator),
|obj, writer| {
obj.describe(&matches, env, writer)?;
if include_events {
clickwriteln!(writer, "\nEvents:");
print_events_for_obj(obj, env, writer)
} else {
Ok(())
}
},
)
}
);