Skip to content
Myr

Move exit code consts into enum

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Previously, the constants defined in `src/exit_codes` weren't being used, and the constants for exit codes were being redefined in the `internals` module. This PR removes the exit code consts and instead uses an enum defined in `src/exit_codes`. This centralizes the definitions of exit codes making them easier to modify and keep track of.

authored by Josh Leeb-du Toit · committed by David Peter · parent f9c4e8d · Browse files · 5 files+21 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+21 added−15 removed

  • other:+21 added−15 removed

5 files+21 added−15 removed

modified:src/exit_codes.rs+13 added-4 removed
1/// exit code 1 represents a general error2pub const ERROR: i32 = 1;3/// exit code 130 represents a process killed by signal SIGINT4pub const SIGINT: i32 = 130;1pub enum ExitCode {2 Error,3 Sigint,4}56impl Into<i32> for ExitCode {7 fn into(self) -> i32 {8 match self {9 ExitCode::Error => 1,10 ExitCode::Sigint => 130,11 }12 }13}
modified:src/internal.rs-6 removed
212 unmodified lines
213214/// Maximum size of the output buffer before flushing results to the console215pub const MAX_BUFFER_LENGTH: usize = 1000;216217/// Exit code representing a general error218pub const EXITCODE_ERROR: i32 = 1;219220/// Exit code representing that the process was killed by SIGINT221pub const EXITCODE_SIGINT: i32 = 130;222217/// Traverse args_os, looking for -exec and replacing it with --exec.218///219/// # Returns220///
260 unmodified lines
modified:src/main.rs+1 added
19 unmodified lines
20extern crate regex_syntax;2122mod app;23mod exec;24mod exit_codes;25pub mod fshelper;26mod internal;27pub mod lscolors;28mod output;
218 unmodified lines
modified:src/output.rs+4 added-3 removed
4 unmodified lines
5// at your option. All files in the project carrying such6// notice may not be copied, modified, or distributed except7// according to those terms.89use exit_codes::ExitCode;10use fshelper::is_executable;10use internal::{FdOptions, EXITCODE_ERROR, EXITCODE_SIGINT};11use internal::FdOptions;12use lscolors::LsColors;1314use std::io::{self, Write};15use std::ops::Deref;
28 unmodified lines
44 };4546 if r.is_err() {47 // Probably a broken pipe. Exit gracefully.47 process::exit(EXITCODE_ERROR);48 process::exit(ExitCode::Error.into());49 }50}5152fn print_entry_colorized(
33 unmodified lines
86 };8788 if wants_to_quit.load(Ordering::Relaxed) {89 write!(handle, "\n")?;89 process::exit(EXITCODE_SIGINT);90 process::exit(ExitCode::Sigint.into());91 }92 }9394 if config.null_separator {
44 unmodified lines
modified:src/walk.rs+3 added-2 removed
7 unmodified lines
89extern crate ctrlc;1011use exec;12use exit_codes::ExitCode;13use fshelper;13use internal::{print_error, print_error_and_exit, FdOptions, EXITCODE_SIGINT, MAX_BUFFER_LENGTH};14use internal::{print_error, print_error_and_exit, FdOptions, MAX_BUFFER_LENGTH};15use output;1617use std::error::Error;18use std::path::PathBuf;
299 unmodified lines
318 // Wait for the receiver thread to print out all results.319 receiver_thread.join().unwrap();320321 if wants_to_quit.load(Ordering::Relaxed) {321 process::exit(EXITCODE_SIGINT);322 process::exit(ExitCode::Sigint.into());323 }324}