From 3fe04a2ddcad9d1fa4c3f3b7265aeb27ec35685f Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Fri, 8 Nov 2019 11:23:19 +0000 Subject: [PATCH] main: Add --version CLI option Support `--version` which dumps the announce message and exits. Fixes: #80. Signed-off-by: James O. D. Hunt --- src/agent/src/main.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index fa1b3181f..a2014bde5 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -83,14 +83,21 @@ fn announce(logger: &Logger) { Ok(s) => s, Err(_) => String::from(""), }; + info!(logger, "announce"; "agent-commit" => commit.as_str(), + + // Avoid any possibility of confusion with the old agent + "agent-type" => "rust", + "agent-version" => version::AGENT_VERSION, "api-version" => version::API_VERSION, ); } fn main() -> Result<()> { + let args: Vec = env::args().collect(); + env::set_var("RUST_BACKTRACE", "full"); lazy_static::initialize(&SHELLS); @@ -106,6 +113,13 @@ 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" => "grpc"))); @@ -306,7 +320,7 @@ use nix::fcntl::{self, OFlag}; use nix::sys::stat::Mode; use std::os::unix::io::{FromRawFd, RawFd}; use std::path::PathBuf; -use std::process::{Command, Stdio}; +use std::process::{exit, Command, Stdio}; fn setup_debug_console(shells: Vec) -> Result<()> { for shell in shells.iter() {