Skip to content

Commit

Permalink
refactor the main() function
Browse files Browse the repository at this point in the history
  • Loading branch information
cat-in-136 committed Mar 6, 2021
1 parent 8682daf commit 98c41a0
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn process(
Ok(())
}

fn main() {
fn parse_arg() -> Result<(Option<String>, Option<PathBuf>, Option<String>, AutoReqMode), Error> {
let program = env::args().nth(0).unwrap();

let mut opts = Options::new();
Expand Down Expand Up @@ -91,13 +91,19 @@ fn main() {
opt_matches
.opt_str("auto-req")
.unwrap_or("auto".to_string()),
)
.unwrap_or_else(|err| {
eprintln!("{}: {}", program, err);
std::process::exit(1);
});
)?;

process(target_arch, target_file, package, auto_req_mode).unwrap_or_else(|err| {
Ok((target_arch, target_file, package, auto_req_mode))
}

fn main() {
(|| -> Result<(), Error> {
let (target_arch, target_file, package, auto_req_mode) = parse_arg()?;
process(target_arch, target_file, package, auto_req_mode)?;
Ok(())
})()
.unwrap_or_else(|err| {
let program = env::args().nth(0).unwrap();
eprintln!("{}: {}", program, err);
if cfg!(debug_assertions) {
panic!("{:?}", err);
Expand Down

0 comments on commit 98c41a0

Please sign in to comment.