aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Goldstein <cardoe@cardoe.com>2018-06-29 11:10:36 -0500
committerDoug Goldstein <cardoe@cardoe.com>2018-06-29 11:10:36 -0500
commit355f54dbdcc6c625f5a8d10f413df1cb64d15b56 (patch)
tree8b2a7a19446f40b6ce12cab042d6626df32e758f
parentmark project as passively maintained (diff)
downloadcargo-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.rs9
-rw-r--r--src/main.rs28
2 files changed, 21 insertions, 16 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 0177556..94448a5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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);
}
}