Skip to content

Commit

Permalink
don't interact with git repo when creating default config
Browse files Browse the repository at this point in the history
also return >0 code if config failed to be created

Fixes #23

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
  • Loading branch information
TomasTomecek committed May 23, 2017
1 parent 089813c commit 5744175
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate clap;
extern crate git2;
extern crate yaml_rust;

use std::io::{self, Write};
use backend::Backend;
use cli::cli;
use conf::{Conf,get_configuration,create_default_config};
Expand All @@ -24,45 +25,57 @@ mod constants;
mod models;


fn main() {
fn run_app() -> Result<(), String> {
let app = cli();
let matches = app.get_matches();

let debug_enabled = matches.is_present("debug");
if debug_enabled { println!("Debug messages are enabled."); }

let repo = match Repository::discover(".") {
Ok(repo) => repo,
// not a git repository, ignore
Err(e) => {
if debug_enabled { println!("This is not a git repository: {:?}", e); }
return ();
}
};

let conf_path: Option<String> = if matches.is_present("config") {
Some(String::from(matches.value_of("config").unwrap()))
} else {
None
};

// create default config command
if matches.is_present(CLI_DEFAULT_CONFIG_SUBC_NAME) {
let p = get_default_config_path();
match create_default_config(&p) {
Ok(path) => {
println!("Configuration file created at \"{}\"", path);
return ();
return Ok(());
}
Err(e) => {
return Err(format!("Failed to create configuration file \"{}\": {}", p.to_str().unwrap(), e));
}
};
} else {
// no command, run primary functionality
let repo = match Repository::discover(".") {
Ok(repo) => repo,
// not a git repository, ignore
Err(e) => {
println!("Failed to create configuration file \"{}\": {}", p.to_str().unwrap(), e);
return ();
if debug_enabled { println!("This is not a git repository: {:?}", e); }
return Ok(());
}
};

let backend = Backend::new(repo, debug_enabled);
let dm: DisplayMaster = DisplayMaster::new(backend, debug_enabled);
let mut conf: Conf = get_configuration(conf_path, dm);
let out: String = conf.populate_values();
println!("{}", out);
}
Ok(())
}

let backend = Backend::new(repo, debug_enabled);
let dm: DisplayMaster = DisplayMaster::new(backend, debug_enabled);
let mut conf: Conf = get_configuration(conf_path, dm);
let out: String = conf.populate_values();
println!("{}", out);
fn main() {
::std::process::exit(match run_app() {
Ok(_) => 0,
Err(err) => {
writeln!(io::stderr(), "{}", err).unwrap();
2
}
});
}

0 comments on commit 5744175

Please sign in to comment.