Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI cleanup #70

Merged
merged 3 commits into from
Dec 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions node/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ pub use config::Config;

use clap::{App, Arg};
use node::utils::{read_file, read_toml};
use slog::*;
use slog::Logger;
use std::io;

pub(super) fn cli(log: &Logger) -> Config {
pub(super) fn cli(_log: &Logger) -> Result<Config, io::Error> {
let app = App::new("Ferret")
.version("0.0.1")
.author("ChainSafe Systems <info@chainsafe.io>")
Expand All @@ -23,24 +24,14 @@ pub(super) fn cli(log: &Logger) -> Config {
)
.get_matches();

if app.is_present("Ferret") {
info!(log, "Ferret was run!");
}

if let Some(ref config_file) = app.value_of("config") {
if let Some(config_file) = app.value_of("config") {
// Read from config file
let toml = match read_file(config_file.to_string()) {
Ok(contents) => contents,
Err(e) => panic!("{:?}", e),
};
let toml = read_file(config_file.to_string())?;

// Parse and return the configuration file
return match read_toml(&toml) {
Ok(contents) => contents,
Err(e) => panic!("{:?}", e),
};
return Ok(read_toml(&toml)?);
};
// TODO in future parse all flags and append to a configuraiton object
// Retrun defaults
Config::default()
Ok(Config::default())
}
2 changes: 1 addition & 1 deletion node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() {
info!(log, "Starting Ferret");

// Capture CLI inputs
let config = cli(&log);
let config = cli(&log).expect("CLI error");

// Create the tokio runtime
let rt = Runtime::new().unwrap();
Expand Down