diff --git a/src/common.rs b/src/common.rs index a799f4a..9fe28ad 100644 --- a/src/common.rs +++ b/src/common.rs @@ -15,7 +15,7 @@ pub(crate) use std::{ num::{ParseFloatError, ParseIntError, TryFromIntError}, ops::{AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}, path::{self, Path, PathBuf}, - process::{self, ExitStatus}, + process::ExitStatus, str::{self, FromStr}, string::FromUtf8Error, sync::Once, diff --git a/src/consts.rs b/src/consts.rs index bf40769..c83c1e7 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -34,7 +34,7 @@ pub(crate) const PROGRESS_CHARS: &str = "█▉▊▋▌▍▎▏ "; /// Digits are ordered from least significant to most significant from /// top to bottom, and then left to right, like so: /// -/// ``` +/// ```text /// ╔═════╗ /// ║ 0 4 ║ /// ║ 1 5 ║ diff --git a/src/env.rs b/src/env.rs index 759ca1f..2ed0bcb 100644 --- a/src/env.rs +++ b/src/env.rs @@ -77,7 +77,7 @@ impl Env { /// To enable logging in those tests, call `Env::initialize_logging()` like /// so: /// - /// ``` + /// ```no_run /// #[test] /// fn foo() { /// Env::initialize_logging(); diff --git a/src/infohash.rs b/src/infohash.rs index d4825a4..5b2d966 100644 --- a/src/infohash.rs +++ b/src/infohash.rs @@ -1,4 +1,4 @@ -use crate::*; +use crate::common::*; #[derive(Debug, Eq, PartialEq, Copy, Clone)] pub(crate) struct Infohash { diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..6a63d11 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,106 @@ +#![deny(clippy::all, clippy::pedantic, clippy::restriction)] +#![allow( + clippy::else_if_without_else, + clippy::enum_glob_use, + clippy::float_arithmetic, + clippy::float_cmp, + clippy::implicit_return, + clippy::indexing_slicing, + clippy::integer_arithmetic, + clippy::integer_division, + clippy::large_enum_variant, + clippy::missing_docs_in_private_items, + clippy::missing_inline_in_public_items, + clippy::needless_pass_by_value, + clippy::non_ascii_literal, + clippy::option_map_unwrap_or_else, + clippy::shadow_reuse, + clippy::struct_excessive_bools, + clippy::too_many_lines, + clippy::unseparated_literal_suffix, + clippy::wildcard_enum_match_arm, + clippy::wildcard_imports +)] + +#[cfg(test)] +#[macro_use] +mod assert_matches; + +#[macro_use] +mod errln; + +#[macro_use] +mod err; + +#[macro_use] +mod out; + +#[macro_use] +mod outln; + +#[cfg(test)] +#[macro_use] +mod test_env; + +#[cfg(test)] +mod test_env_builder; + +#[cfg(test)] +mod capture; + +mod arguments; +mod bytes; +mod common; +mod consts; +mod env; +mod error; +mod file_error; +mod file_info; +mod file_path; +mod file_status; +mod files; +mod hasher; +mod host_port; +mod host_port_parse_error; +mod info; +mod infohash; +mod input; +mod input_stream; +mod input_target; +mod into_u64; +mod into_usize; +mod invariant; +mod lint; +mod linter; +mod magnet_link; +mod md5_digest; +mod metainfo; +mod metainfo_error; +mod mode; +mod options; +mod output_stream; +mod output_target; +mod piece_length_picker; +mod piece_list; +mod platform; +mod platform_interface; +mod print; +mod reckoner; +mod run; +mod sha1_digest; +mod shell; +mod sort_key; +mod sort_order; +mod sort_spec; +mod status; +mod step; +mod style; +mod subcommand; +mod table; +mod torrent_summary; +mod use_color; +mod verifier; +mod walker; +mod xor_args; + +pub use run::run; diff --git a/src/main.rs b/src/main.rs index 1e322eb..9ce15bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,110 +1,5 @@ -#![deny(clippy::all, clippy::pedantic, clippy::restriction)] -#![allow( - clippy::else_if_without_else, - clippy::enum_glob_use, - clippy::float_arithmetic, - clippy::float_cmp, - clippy::implicit_return, - clippy::indexing_slicing, - clippy::integer_arithmetic, - clippy::integer_division, - clippy::large_enum_variant, - clippy::missing_docs_in_private_items, - clippy::needless_pass_by_value, - clippy::non_ascii_literal, - clippy::option_map_unwrap_or_else, - clippy::shadow_reuse, - clippy::too_many_lines, - clippy::unseparated_literal_suffix, - clippy::wildcard_enum_match_arm, - clippy::wildcard_imports, - clippy::struct_excessive_bools -)] - -use crate::common::*; - -#[cfg(test)] -#[macro_use] -mod assert_matches; - -#[macro_use] -mod errln; - -#[macro_use] -mod err; - -#[macro_use] -mod out; - -#[macro_use] -mod outln; - -#[cfg(test)] -#[macro_use] -mod test_env; - -#[cfg(test)] -mod test_env_builder; - -#[cfg(test)] -mod capture; - -mod arguments; -mod bytes; -mod common; -mod consts; -mod env; -mod error; -mod file_error; -mod file_info; -mod file_path; -mod file_status; -mod files; -mod hasher; -mod host_port; -mod host_port_parse_error; -mod info; -mod infohash; -mod input; -mod input_stream; -mod input_target; -mod into_u64; -mod into_usize; -mod invariant; -mod lint; -mod linter; -mod magnet_link; -mod md5_digest; -mod metainfo; -mod metainfo_error; -mod mode; -mod options; -mod output_stream; -mod output_target; -mod piece_length_picker; -mod piece_list; -mod platform; -mod platform_interface; -mod print; -mod reckoner; -mod sha1_digest; -mod shell; -mod sort_key; -mod sort_order; -mod sort_spec; -mod status; -mod step; -mod style; -mod subcommand; -mod table; -mod torrent_summary; -mod use_color; -mod verifier; -mod walker; -mod xor_args; - fn main() { - if let Err(code) = Env::main().status() { - process::exit(code); + if let Err(code) = imdl::run() { + std::process::exit(code); } } diff --git a/src/run.rs b/src/run.rs new file mode 100644 index 0000000..575cc86 --- /dev/null +++ b/src/run.rs @@ -0,0 +1,22 @@ +use crate::common::*; + +/// Entry point into the IMDL binary. +/// +/// Called by `main` in `main.rs`. +/// +/// Constructs an `Env` using `Env::main`, containing the command line +/// arguments, the current working directory, a handle to standard error, +/// standard output, and standard input. +/// +/// Calls `Env::status` which runs the program, prints error messages, and +/// returns a status code in case there was an error. +/// +/// Errors +/// ------ +/// +/// In case of an error, a nonzero status code is returned. This status code can +/// be passed to `std::process::exit`, to exit the process and report its +/// failure to the system. +pub fn run() -> Result<(), i32> { + Env::main().status() +} diff --git a/src/shell.rs b/src/shell.rs index fdc9b04..f43e037 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -1,4 +1,4 @@ -use super::*; +use crate::common::*; use structopt::clap;