From e2952b53547314f9f6a742243c5732537c361058 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Thu, 20 Aug 2020 15:39:57 +0100 Subject: [PATCH] main: Simplify version handling Print a simple version string rather than delaying the output to display a structured version string. The structured output is potentially more useful but: - This output is not consistent with other components. - Delaying the output makes `--version` unusable in some environments (since a lot of setup is called before the version string can be output). Signed-off-by: James O. D. Hunt --- src/agent/src/main.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index 79ed6753d..ba21f53f5 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -105,6 +105,19 @@ fn announce(logger: &Logger) { fn main() -> Result<()> { let args: Vec = env::args().collect(); + + if args.len() == 2 && args[1] == "--version" { + println!( + "{} version {} (api version: {}, commit version: {}, type: rust)", + NAME, + version::AGENT_VERSION, + version::API_VERSION, + env::var("VERSION_COMMIT").unwrap_or("unknown".to_string()) + ); + + exit(0); + } + if args.len() == 2 && args[1] == "init" { rustjail::container::init_child(); exit(0); @@ -177,13 +190,6 @@ fn main() -> Result<()> { announce(&logger); - if args.len() == 2 && args[1] == "--version" { - // force logger to flush - drop(logger); - - exit(0); - } - // This "unused" variable is required as it enables the global (and crucially static) logger, // which is required to satisfy the the lifetime constraints of the auto-generated gRPC code. let _guard = slog_scope::set_global_logger(logger.new(o!("subsystem" => "rpc")));