Skip to content

Commit d6b33ce

Browse files
authored
Pull up clap to 4.0 series (#1041)
Signed-off-by: Cyril Plisko <[email protected]> Signed-off-by: Cyril Plisko <[email protected]>
1 parent 6f14058 commit d6b33ce

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

examples/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ tower-http = { version = "0.3.2", features = ["trace", "decompression-gzip"] }
5050
hyper = { version = "0.14.13", features = ["client", "http1", "stream", "tcp"] }
5151
thiserror = "1.0.29"
5252
backoff = "0.4.0"
53-
clap = { version = "3.1.9", default-features = false, features = ["std", "cargo", "derive"] }
53+
clap = { version = "4.0", default-features = false, features = ["std", "cargo", "derive"] }
5454
edit = "0.1.3"
5555
tokio-stream = { version = "0.1.9", features = ["net"] }
5656

examples/kubectl.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,43 @@ use tracing::*;
2121

2222
#[derive(clap::Parser)]
2323
struct App {
24-
#[clap(long, short, arg_enum, default_value_t)]
24+
#[arg(long, short, default_value_t = OutputMode::Pretty)]
2525
output: OutputMode,
26-
#[clap(long, short)]
26+
#[arg(long, short)]
2727
file: Option<std::path::PathBuf>,
28-
#[clap(long, short = 'l')]
28+
#[arg(long, short = 'l')]
2929
selector: Option<String>,
30-
#[clap(long, short)]
30+
#[arg(long, short)]
3131
namespace: Option<String>,
32-
#[clap(long, short = 'A')]
32+
#[arg(long, short = 'A')]
3333
all: bool,
34-
#[clap(arg_enum)]
3534
verb: Verb,
3635
resource: Option<String>,
3736
name: Option<String>,
3837
}
3938

40-
#[derive(clap::ArgEnum, Clone, PartialEq, Eq)]
39+
#[derive(Clone, PartialEq, Eq, clap::ValueEnum)]
4140
enum OutputMode {
4241
Pretty,
4342
Yaml,
4443
}
45-
impl Default for OutputMode {
46-
fn default() -> Self {
47-
Self::Pretty
44+
45+
impl OutputMode {
46+
fn as_str(&self) -> &'static str {
47+
match self {
48+
Self::Pretty => "pretty",
49+
Self::Yaml => "yaml",
50+
}
51+
}
52+
}
53+
54+
impl std::fmt::Display for OutputMode {
55+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56+
f.pad(self.as_str())
4857
}
4958
}
50-
#[derive(clap::ArgEnum, Clone, PartialEq, Eq, Debug)]
59+
60+
#[derive(Clone, PartialEq, Eq, Debug, clap::ValueEnum)]
5161
enum Verb {
5262
Get,
5363
Delete,

0 commit comments

Comments
 (0)