Check environment for key and url values
Adds a check for the GRID_DAEMON_KEY and GRID_DAEMON_ENDPOINT
environment variables to the CLI.
@@ -31,6 +31,8 @@ mod splinter;
mod transaction;
mod yaml_parser;
+use std::env;
+
use clap::ArgMatches;
use flexi_logger::{LogSpecBuilder, Logger};
use grid_sdk::protocol::pike::{
@@ -51,6 +53,9 @@ use actions::admin;
const APP_NAME: &str = env!("CARGO_PKG_NAME");
const VERSION: &str = env!("CARGO_PKG_VERSION");
+const GRID_DAEMON_KEY: &str = "GRID_DAEMON_KEY";
+const GRID_DAEMON_ENDPOINT: &str = "GRID_DAEMON_ENDPOINT";
+
fn run() -> Result<(), CliError> {
#[allow(unused_mut)]
let mut app = clap_app!(myapp =>
@@ -227,9 +232,16 @@ fn run() -> Result<(), CliError> {
Logger::with(log_spec_builder.build()).start()?;
- let url = matches.value_of("url").unwrap_or("http://localhost:8000");
+ let url = matches
+ .value_of("url")
+ .map(String::from)
+ .or_else(|| env::var(GRID_DAEMON_ENDPOINT).ok())
+ .unwrap_or_else(|| String::from("http://localhost:8000"));
- let key = matches.value_of("key").map(ToString::to_string);
+ let key = matches
+ .value_of("key")
+ .map(String::from)
+ .or_else(|| env::var(GRID_DAEMON_KEY).ok());
let wait = value_t!(matches, "wait", u64).unwrap_or(0);
