main: Add --version CLI option

Support `--version` which dumps the announce message and exits.

Fixes: #80.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
James O. D. Hunt
2019-11-08 11:23:19 +00:00
parent cb1849cd2c
commit 3fe04a2ddc

View File

@@ -83,14 +83,21 @@ fn announce(logger: &Logger) {
Ok(s) => s, Ok(s) => s,
Err(_) => String::from(""), Err(_) => String::from(""),
}; };
info!(logger, "announce"; info!(logger, "announce";
"agent-commit" => commit.as_str(), "agent-commit" => commit.as_str(),
// Avoid any possibility of confusion with the old agent
"agent-type" => "rust",
"agent-version" => version::AGENT_VERSION, "agent-version" => version::AGENT_VERSION,
"api-version" => version::API_VERSION, "api-version" => version::API_VERSION,
); );
} }
fn main() -> Result<()> { fn main() -> Result<()> {
let args: Vec<String> = env::args().collect();
env::set_var("RUST_BACKTRACE", "full"); env::set_var("RUST_BACKTRACE", "full");
lazy_static::initialize(&SHELLS); lazy_static::initialize(&SHELLS);
@@ -106,6 +113,13 @@ fn main() -> Result<()> {
announce(&logger); 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, // 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. // 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"))); 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 nix::sys::stat::Mode;
use std::os::unix::io::{FromRawFd, RawFd}; use std::os::unix::io::{FromRawFd, RawFd};
use std::path::PathBuf; use std::path::PathBuf;
use std::process::{Command, Stdio}; use std::process::{exit, Command, Stdio};
fn setup_debug_console(shells: Vec<String>) -> Result<()> { fn setup_debug_console(shells: Vec<String>) -> Result<()> {
for shell in shells.iter() { for shell in shells.iter() {