diff --git a/cli/src/build.rs b/cli/src/build.rs index 26ddc1e37c..1682aff916 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -26,6 +26,16 @@ pub enum BuildOutcome { Errors, } +impl BuildOutcome { + pub fn status_code(&self) -> i32 { + match self { + Self::NoProblems => 0, + Self::OnlyWarnings => 1, + Self::Errors => 2, + } + } +} + pub struct BuiltFile { pub binary_path: PathBuf, pub outcome: BuildOutcome, diff --git a/cli/src/lib.rs b/cli/src/lib.rs index d5a80eb53f..1cd2ea0eab 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -196,13 +196,6 @@ pub fn build(target: &Triple, matches: &ArgMatches, config: BuildConfig) -> io:: .strip_prefix(env::current_dir().unwrap()) .unwrap_or(&binary_path); - // Return a nonzero exit code if there were problems - let status_code = match outcome { - BuildOutcome::NoProblems => 0, - BuildOutcome::OnlyWarnings => 1, - BuildOutcome::Errors => 2, - }; - // No need to waste time freeing this memory, // since the process is about to exit anyway. std::mem::forget(arena); @@ -213,7 +206,8 @@ pub fn build(target: &Triple, matches: &ArgMatches, config: BuildConfig) -> io:: total_time.as_millis() ); - Ok(status_code) + // Return a nonzero exit code if there were problems + Ok(outcome.status_code()) } BuildAndRun { roc_file_arg_index } => { let mut cmd = Command::new(binary_path); @@ -232,7 +226,7 @@ pub fn build(target: &Triple, matches: &ArgMatches, config: BuildConfig) -> io:: } match outcome { - BuildOutcome::Errors => Ok(2), + BuildOutcome::Errors => Ok(outcome.status_code()), _ => roc_run(cmd.current_dir(original_cwd)), } }