diff options
author | 2018-06-29 11:10:36 -0500 | |
---|---|---|
committer | 2018-06-29 11:10:36 -0500 | |
commit | 355f54dbdcc6c625f5a8d10f413df1cb64d15b56 (patch) | |
tree | 8b2a7a19446f40b6ce12cab042d6626df32e758f | |
parent | mark project as passively maintained (diff) | |
download | cargo-ebuild-355f54dbdcc6c625f5a8d10f413df1cb64d15b56.tar.gz cargo-ebuild-355f54dbdcc6c625f5a8d10f413df1cb64d15b56.tar.bz2 cargo-ebuild-355f54dbdcc6c625f5a8d10f413df1cb64d15b56.zip |
remove more Cargo usage from main binary
Remove the instantiation of Cargo's config from the main binary and move
it to the library component.
-rw-r--r-- | src/lib.rs | 9 | ||||
-rw-r--r-- | src/main.rs | 28 |
2 files changed, 21 insertions, 16 deletions
@@ -59,7 +59,10 @@ fn resolve<'a>( Ok((packages, resolve)) } -pub fn run(verbose: u32, quiet: bool, config: &Config) -> CliResult { +pub fn run(verbose: u32, quiet: bool) -> CliResult { + // create a default Cargo config + let config = Config::default()?; + config.configure( verbose, Some(quiet), @@ -72,11 +75,11 @@ pub fn run(verbose: u32, quiet: bool, config: &Config) -> CliResult { )?; // Load the workspace and current package - let workspace = workspace(config, None)?; + let workspace = workspace(&config, None)?; let package = workspace.current()?; // Resolve all dependencies (generate or use Cargo.lock as necessary) - let mut registry = registry(config, &package)?; + let mut registry = registry(&config, &package)?; let resolve = resolve(&mut registry, &workspace)?; // build the crates the package needs diff --git a/src/main.rs b/src/main.rs index 658debc..ee8f7c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,9 +13,9 @@ extern crate cargo_ebuild; #[macro_use] extern crate structopt; -use cargo::core::shell::Shell; -use cargo::Config; +use cargo::util::CliError; use cargo_ebuild::run; +use std::process; use structopt::clap::AppSettings; use structopt::StructOpt; @@ -47,17 +47,19 @@ enum Opt { fn main() { let Opt::Ebuild(opt) = Opt::from_args(); - // create a default Cargo config - let mut config = match Config::default() { - Ok(cfg) => cfg, - Err(e) => { - let mut shell = Shell::new(); - cargo::exit_with_error(e.into(), &mut shell) - } - }; - // run the actual code - if let Err(e) = run(opt.verbose as u32, opt.quiet, &mut config) { - cargo::exit_with_error(e.into(), &mut *config.shell()) + if let Err(e) = run(opt.verbose as u32, opt.quiet) { + // break apart the error + let CliError { + error, + exit_code, + unknown: _unknown, + } = e; + // display a msg if we got one + if let Some(msg) = error { + eprintln!("{}", msg); + } + // exit appropriately + process::exit(exit_code); } } |