Skip to content

Commit

Permalink
Merge pull request #769 from saschagrunert/version-enum
Browse files Browse the repository at this point in the history
Make version verbosity an enum
  • Loading branch information
openshift-merge-robot authored Oct 4, 2022
2 parents e58ae5a + b4888da commit 5787e79
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
32 changes: 26 additions & 6 deletions conmon-rs/server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ macro_rules! prefix {
};
}

/// Specifies the full version output option.
pub const VERSION_FULL: &str = "full";

#[derive(CopyGetters, Debug, Deserialize, Eq, Getters, Parser, PartialEq, Serialize, Setters)]
#[serde(rename_all = "kebab-case")]
#[clap(
Expand All @@ -24,17 +21,17 @@ pub const VERSION_FULL: &str = "full";

/// An OCI container runtime monitor.
pub struct Config {
#[get = "pub"]
#[get_copy = "pub"]
#[clap(
default_missing_value("default"),
env(concat!(prefix!(), "VERSION")),
long("version"),
possible_values(["default", VERSION_FULL]),
possible_values(Verbosity::iter().map(|x| x.into()).collect::<Vec<&str>>()),
short('v'),
value_name("VERBOSITY")
)]
/// Show version information, specify "full" for verbose output.
version: Option<String>,
version: Option<Verbosity>,

#[get = "pub"]
#[clap(
Expand Down Expand Up @@ -112,6 +109,29 @@ pub struct Config {
cgroup_manager: CgroupManager,
}

#[derive(
Clone,
Copy,
Debug,
Deserialize,
EnumIter,
EnumString,
Eq,
IntoStaticStr,
Hash,
PartialEq,
Serialize,
)]
#[strum(serialize_all = "lowercase")]
/// Available verbosity levels.
pub enum Verbosity {
/// The default output verbosity.
Default,

/// The full output verbosity.
Full,
}

#[derive(
Clone,
Copy,
Expand Down
4 changes: 2 additions & 2 deletions conmon-rs/server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
child_reaper::ChildReaper,
config::{CgroupManager, Config, LogDriver, VERSION_FULL},
config::{CgroupManager, Config, LogDriver, Verbosity},
container_io::{ContainerIO, ContainerIOType},
init::{DefaultInit, Init},
listener::{DefaultListener, Listener},
Expand Down Expand Up @@ -54,7 +54,7 @@ impl Server {
};

if let Some(v) = server.config().version() {
Version::new(v == VERSION_FULL).print();
Version::new(v == Verbosity::Full).print();
process::exit(0);
}

Expand Down

0 comments on commit 5787e79

Please sign in to comment.