diff options
author | Nick Gerace <nickagerace@gmail.com> | 2023-04-07 13:55:06 -0400 |
---|---|---|
committer | Nick Gerace <nickagerace@gmail.com> | 2023-04-19 10:05:58 -0400 |
commit | 3fa4afc0d385c4a5e2262364c6cee06ac21cc339 (patch) | |
tree | 0882b6d99cc845ea43c2fe5a750cc27f7515995f | |
parent | 1d768381bd0fb16684e64911ebe4eb7c67f6ba50 (diff) | |
download | gfold-3fa4afc0d385c4a5e2262364c6cee06ac21cc339.zip |
Split gfold into gfold and libgfold
Split gfold into gfold and libgfold to increase the number of
compilation units and allow for external use of the library. Keep
libgfold unpublished until logging, error types, etc. is handled
properly.
Signed-off-by: Nick Gerace <nickagerace@gmail.com>
-rw-r--r-- | .cargo/config | 2 | ||||
-rw-r--r-- | Cargo.lock | 124 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | bin/gfold/Cargo.toml (renamed from crates/gfold/Cargo.toml) | 16 | ||||
-rw-r--r-- | bin/gfold/src/cli.rs (renamed from crates/gfold/src/cli.rs) | 17 | ||||
-rw-r--r-- | bin/gfold/src/config.rs (renamed from crates/gfold/src/config.rs) | 0 | ||||
-rw-r--r-- | bin/gfold/src/display.rs (renamed from crates/gfold/src/display.rs) | 2 | ||||
-rw-r--r-- | bin/gfold/src/display/color.rs (renamed from crates/gfold/src/display/color.rs) | 2 | ||||
-rw-r--r-- | bin/gfold/src/main.rs | 31 | ||||
-rw-r--r-- | bin/xtask/Cargo.toml (renamed from crates/xtask/Cargo.toml) | 0 | ||||
-rw-r--r-- | bin/xtask/src/main.rs (renamed from crates/xtask/src/main.rs) | 0 | ||||
-rw-r--r-- | bin/xtask/src/task.rs (renamed from crates/xtask/src/task.rs) | 0 | ||||
-rw-r--r-- | bin/xtask/src/task/bloat.rs (renamed from crates/xtask/src/task/bloat.rs) | 0 | ||||
-rw-r--r-- | bin/xtask/src/task/build.rs (renamed from crates/xtask/src/task/build.rs) | 0 | ||||
-rw-r--r-- | bin/xtask/src/task/build_release.rs (renamed from crates/xtask/src/task/build_release.rs) | 0 | ||||
-rw-r--r-- | bin/xtask/src/task/ci.rs (renamed from crates/xtask/src/task/ci.rs) | 2 | ||||
-rw-r--r-- | bin/xtask/src/task/loose_bench.rs (renamed from crates/xtask/src/task/loose_bench.rs) | 0 | ||||
-rw-r--r-- | bin/xtask/src/task/prepare.rs (renamed from crates/xtask/src/task/prepare.rs) | 0 | ||||
-rw-r--r-- | bin/xtask/src/task/scan.rs (renamed from crates/xtask/src/task/scan.rs) | 0 | ||||
-rw-r--r-- | bin/xtask/src/task/size.rs (renamed from crates/xtask/src/task/size.rs) | 0 | ||||
-rw-r--r-- | crates/gfold/src/run.rs | 25 | ||||
-rw-r--r-- | lib/libgfold/Cargo.toml | 28 | ||||
-rw-r--r-- | lib/libgfold/src/collector.rs (renamed from crates/gfold/src/collector.rs) | 17 | ||||
-rw-r--r-- | lib/libgfold/src/collector/target.rs (renamed from crates/gfold/src/collector/target.rs) | 0 | ||||
-rw-r--r-- | lib/libgfold/src/lib.rs (renamed from crates/gfold/src/main.rs) | 56 | ||||
-rw-r--r-- | lib/libgfold/src/repository_view.rs (renamed from crates/gfold/src/repository_view.rs) | 5 | ||||
-rw-r--r-- | lib/libgfold/src/repository_view/submodule_view.rs (renamed from crates/gfold/src/repository_view/submodule_view.rs) | 0 | ||||
-rw-r--r-- | lib/libgfold/src/status.rs (renamed from crates/gfold/src/status.rs) | 0 |
28 files changed, 169 insertions, 162 deletions
diff --git a/.cargo/config b/.cargo/config index 337141e..88c4f89 100644 --- a/.cargo/config +++ b/.cargo/config @@ -2,4 +2,4 @@ rustdocflags = "--document-private-items" [alias] -xtask = "run -q --manifest-path ./crates/xtask/Cargo.toml --"
\ No newline at end of file +xtask = "run -q --manifest-path ./bin/xtask/Cargo.toml --" @@ -19,42 +19,51 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "anstream" -version = "0.2.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "342258dd14006105c2b75ab1bd7543a03bdf0cfc94383303ac212a04939dff6f" +checksum = "9e579a7752471abc2a8268df8b20005e3eadd975f585398f17efcfd8d4927371" dependencies = [ "anstyle", "anstyle-parse", + "anstyle-query", "anstyle-wincon", - "concolor-override", - "concolor-query", + "colorchoice", "is-terminal", "utf8parse", ] [[package]] name = "anstyle" -version = "0.3.5" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2" +checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" [[package]] name = "anstyle-parse" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116" +checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" dependencies = [ "utf8parse", ] [[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] name = "anstyle-wincon" -version = "0.2.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa" +checksum = "4bcd8291a340dd8ac70e18878bc4501dd7b4ff970cfa21c207d36ece51ea88fd" dependencies = [ "anstyle", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -110,9 +119,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.2.1" +version = "4.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046ae530c528f252094e4a77886ee1374437744b2bff1497aa898bbddbbb29b3" +checksum = "49f9152d70e42172fdb87de2efd7327160beee37886027cf86f30a233d5b30b4" dependencies = [ "clap_builder", "clap_derive", @@ -121,9 +130,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.2.1" +version = "4.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "223163f58c9a40c3b0a43e1c4b50a9ce09f007ea2cb1ec258a687945b4b7929f" +checksum = "e067b220911598876eb55d52725ddcc201ffe3f0904018195973bc5b012ea2ca" dependencies = [ "anstream", "anstyle", @@ -141,7 +150,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.15", ] [[package]] @@ -151,25 +160,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" [[package]] -name = "concolor-override" +name = "colorchoice" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f" - -[[package]] -name = "concolor-query" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf" -dependencies = [ - "windows-sys 0.45.0", -] +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "crossbeam-channel" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" dependencies = [ "cfg-if", "crossbeam-utils", @@ -262,13 +262,13 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" dependencies = [ "errno-dragonfly", "libc", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -318,13 +318,10 @@ dependencies = [ "clap", "dirs", "env_logger", - "git2", + "libgfold", "log", - "pretty_assertions", - "rayon", "serde", "serde_json", - "tempfile", "termcolor", "thiserror", "toml", @@ -338,9 +335,9 @@ checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" [[package]] name = "git2" -version = "0.16.1" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf7f68c2995f392c49fffb4f95ae2c873297830eb25c6bc4c114ce8f4562acc" +checksum = "8b7905cdfe33d31a88bb2e8419ddd054451f5432d1da9eaf2ac7804ee1ea12d5" dependencies = [ "bitflags", "libc", @@ -456,10 +453,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" [[package]] +name = "libgfold" +version = "0.1.0" +dependencies = [ + "anyhow", + "env_logger", + "git2", + "log", + "pretty_assertions", + "rayon", + "serde", + "tempfile", + "thiserror", +] + +[[package]] name = "libgit2-sys" -version = "0.14.2+1.5.1" +version = "0.15.1+1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f3d95f6b51075fe9810a7ae22c7095f12b98005ab364d8544797a825ce946a4" +checksum = "fb4577bde8cdfc7d6a2a4bcb7b049598597de33ffd337276e9c7db6cd4a2cee7" dependencies = [ "cc", "libc", @@ -481,9 +493,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" +checksum = "3f508063cc7bb32987c71511216bd5a32be15bccb6a80b52df8b9d7f01fc3aa2" [[package]] name = "log" @@ -647,15 +659,15 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4a36c42d1873f9a77c53bde094f9664d9891bc604a45b4798fd2c389ed12e5b" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.37.8" +version = "0.37.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aef160324be24d31a62147fae491c14d2204a3865c7ca8c3b0d7f7bcb3ea635" +checksum = "722529a737f5a942fdbac3a46cee213053196737c5eaa3386d52e85b786f2659" dependencies = [ "bitflags", "errno", @@ -685,29 +697,29 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.159" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" +checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.159" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" +checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.15", ] [[package]] name = "serde_json" -version = "1.0.95" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" dependencies = [ "itoa", "ryu", @@ -764,9 +776,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.13" +version = "2.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec" +checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" dependencies = [ "proc-macro2", "quote", @@ -812,7 +824,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.15", ] [[package]] @@ -1,6 +1,6 @@ [workspace] -members = ["crates/gfold", "crates/xtask"] -default-members = ["crates/gfold"] +members = ["bin/gfold", "bin/xtask", "lib/libgfold"] +default-members = ["bin/gfold"] [profile.release.package.gfold] codegen-units = 1 diff --git a/crates/gfold/Cargo.toml b/bin/gfold/Cargo.toml index 79201aa..5e83119 100644 --- a/crates/gfold/Cargo.toml +++ b/bin/gfold/Cargo.toml @@ -1,31 +1,27 @@ [package] +name = "gfold" +version = "4.3.3" +edition = "2021" + authors = ["Nick Gerace <nickagerace@gmail.com>"] categories = ["command-line-utilities", "command-line-interface"] description = "CLI tool to help keep track of your Git repositories." homepage = "https://nickgerace.dev" keywords = ["git", "cli"] license = "Apache-2.0" -name = "gfold" readme = "../../README.md" repository = "https://github.com/nickgerace/gfold/" -edition = "2021" -version = "4.3.3" - [dependencies] +libgfold = { path = "../../lib/libgfold" } + anyhow = { version = "1.0", features = ["backtrace"] } clap = { version = "4.2", features = ["derive"] } dirs = "5.0" env_logger = { version = "0.10", features = ["humantime"], default_features = false } -git2 = { version = "0.16", default_features = false } log = "0.4" -rayon = "1.7" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" termcolor = "1.2" thiserror = "1.0" toml = "0.7" - -[dev-dependencies] -pretty_assertions = "1.3" -tempfile = "3.5" diff --git a/crates/gfold/src/cli.rs b/bin/gfold/src/cli.rs index 6c32848..dbc9f66 100644 --- a/crates/gfold/src/cli.rs +++ b/bin/gfold/src/cli.rs @@ -2,12 +2,13 @@ //! settings and environment. use clap::Parser; +use libgfold::RepositoryCollector; use log::debug; use std::env; use thiserror::Error; use crate::config::{ColorMode, Config, DisplayMode}; -use crate::run::RunHarness; +use crate::display::DisplayHarness; const HELP: &str = "\ More information: https://github.com/nickgerace/gfold @@ -77,8 +78,7 @@ impl CliHarness { Self { cli } } - /// Merge configurations as needed, and call - /// [`RunHarness::run()`](crate::run::RunHarness::run()) with the resulting [`Config`]. + /// Merge configurations as needed, collect results and display them. pub fn run(&self) -> anyhow::Result<()> { let mut config = match self.cli.ignore_config_file { true => Config::try_config_default()?, @@ -114,8 +114,15 @@ impl CliHarness { match &self.cli.dry_run { true => config.print()?, false => { - let run_harness = RunHarness::new(&config); - run_harness.run()?; + let (include_email, include_submodules) = match config.display_mode { + DisplayMode::Classic => (false, false), + DisplayMode::Json => (true, true), + DisplayMode::Standard => (true, false), + }; + let repository_collection = + RepositoryCollector::run(&config.path, include_email, include_submodules)?; + let display_harness = DisplayHarness::new(config.display_mode, config.color_mode); + display_harness.run(&repository_collection)?; } } Ok(()) diff --git a/crates/gfold/src/config.rs b/bin/gfold/src/config.rs index b865388..b865388 100644 --- a/crates/gfold/src/config.rs +++ b/bin/gfold/src/config.rs diff --git a/crates/gfold/src/display.rs b/bin/gfold/src/display.rs index e66fc41..041e57c 100644 --- a/crates/gfold/src/display.rs +++ b/bin/gfold/src/display.rs @@ -1,13 +1,13 @@ //! This module contains the functionality for displaying reports to `stdout`. use color::ColorHarness; +use libgfold::RepositoryCollection; use log::debug; use log::warn; use std::io; use std::path::{Path, PathBuf}; use thiserror::Error; -use crate::collector::RepositoryCollection; use crate::config::{ColorMode, DisplayMode}; mod color; diff --git a/crates/gfold/src/display/color.rs b/bin/gfold/src/display/color.rs index 1e53d41..f264cd2 100644 --- a/crates/gfold/src/display/color.rs +++ b/bin/gfold/src/display/color.rs @@ -1,11 +1,11 @@ //! This module provides a harness for non-trivial displays of information to `stdout`. +use libgfold::Status; use std::io; use std::io::Write; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; use crate::config::ColorMode; -use crate::status::Status; /// This harness provides methods to write to `stdout`. It maps the internal [`ColorMode`] type to /// our dependency's [`ColorChoice`] type due to discrepancies in behavior and naming. diff --git a/bin/gfold/src/main.rs b/bin/gfold/src/main.rs new file mode 100644 index 0000000..68e5a77 --- /dev/null +++ b/bin/gfold/src/main.rs @@ -0,0 +1,31 @@ +//! [gfold](https://github.com/nickgerace/gfold) is a CLI-driven application that helps you keep +//! track of multiple Git repositories. The source code uses private modules rather than leveraging +//! a library via `lib.rs`. + +#![warn(missing_docs, clippy::missing_errors_doc, clippy::missing_panics_doc)] + +use env_logger::Builder; +use log::debug; +use log::LevelFilter; +use std::env; + +use crate::cli::CliHarness; + +mod cli; +mod config; +mod display; + +/// Initializes the logger based on the debug flag and `RUST_LOG` environment variable and uses +/// the [`CliHarness`] to generate a [`Config`](config::Config). Then, this calls +/// [`CliHarness::run()`]. +fn main() -> anyhow::Result<()> { + match env::var("RUST_LOG").is_err() { + true => Builder::new().filter_level(LevelFilter::Off).init(), + false => env_logger::init(), + } + debug!("initialized logger"); + + let cli_harness = CliHarness::new(); + cli_harness.run()?; + Ok(()) +} diff --git a/crates/xtask/Cargo.toml b/bin/xtask/Cargo.toml index 901a138..901a138 100644 --- a/crates/xtask/Cargo.toml +++ b/bin/xtask/Cargo.toml diff --git a/crates/xtask/src/main.rs b/bin/xtask/src/main.rs index c1d7d5a..c1d7d5a 100644 --- a/crates/xtask/src/main.rs +++ b/bin/xtask/src/main.rs diff --git a/crates/xtask/src/task.rs b/bin/xtask/src/task.rs index d5d4bc9..d5d4bc9 100644 --- a/crates/xtask/src/task.rs +++ b/bin/xtask/src/task.rs diff --git a/crates/xtask/src/task/bloat.rs b/bin/xtask/src/task/bloat.rs index 7880036..7880036 100644 --- a/crates/xtask/src/task/bloat.rs +++ b/bin/xtask/src/task/bloat.rs diff --git a/crates/xtask/src/task/build.rs b/bin/xtask/src/task/build.rs index e1ea8a2..e1ea8a2 100644 --- a/crates/xtask/src/task/build.rs +++ b/bin/xtask/src/task/build.rs diff --git a/crates/xtask/src/task/build_release.rs b/bin/xtask/src/task/build_release.rs index 64b5e63..64b5e63 100644 --- a/crates/xtask/src/task/build_release.rs +++ b/bin/xtask/src/task/build_release.rs diff --git a/crates/xtask/src/task/ci.rs b/bin/xtask/src/task/ci.rs index 979f499..96926de 100644 --- a/crates/xtask/src/task/ci.rs +++ b/bin/xtask/src/task/ci.rs @@ -12,7 +12,7 @@ impl TaskRunner for RunCi { None, )?; harness.cargo("doc --all --no-deps", Some(("RUSTDOCFLAGS", "-Dwarnings")))?; - harness.cargo("test --all-targets", None)?; + harness.cargo("test --all-targets --workspace", None)?; harness.cargo("build --locked --all-targets", None)?; Ok(()) } diff --git a/crates/xtask/src/task/loose_bench.rs b/bin/xtask/src/task/loose_bench.rs index 91c0ee7..91c0ee7 100644 --- a/crates/xtask/src/task/loose_bench.rs +++ b/bin/xtask/src/task/loose_bench.rs diff --git a/crates/xtask/src/task/prepare.rs b/bin/xtask/src/task/prepare.rs index eef2506..eef2506 100644 --- a/crates/xtask/src/task/prepare.rs +++ b/bin/xtask/src/task/prepare.rs diff --git a/crates/xtask/src/task/scan.rs b/bin/xtask/src/task/scan.rs index 207bcc2..207bcc2 100644 --- a/crates/xtask/src/task/scan.rs +++ b/bin/xtask/src/task/scan.rs diff --git a/crates/xtask/src/task/size.rs b/bin/xtask/src/task/size.rs index b8ee730..b8ee730 100644 --- a/crates/xtask/src/task/size.rs +++ b/bin/xtask/src/task/size.rs diff --git a/crates/gfold/src/run.rs b/crates/gfold/src/run.rs deleted file mode 100644 index f168761..0000000 --- a/crates/gfold/src/run.rs +++ /dev/null @@ -1,25 +0,0 @@ -//! This module contains the execution logic for generating reports and displaying them to `stdout`. - -use crate::collector::RepositoryCollector; -use crate::config::Config; -use crate::display::DisplayHarness; - -/// This struct provides the primary entrypoint for this crate. It takes a given config and performs -/// the end-to-end workflow using it. At this point, all CLI and config file options should be -/// set, merged, ignored, etc. -pub struct RunHarness<'config> { - config: &'config Config, -} - -impl<'config> RunHarness<'config> { - pub fn new(config: &'config Config) -> Self { - Self { config } - } - - pub fn run(&self) -> anyhow::Result<()> { - let repository_collection = - RepositoryCollector::run(&self.config.path, self.config.display_mode)?; - let display_harness = DisplayHarness::new(self.config.display_mode, self.config.color_mode); - display_harness.run(&repository_collection) - } -} diff --git a/lib/libgfold/Cargo.toml b/lib/libgfold/Cargo.toml new file mode 100644 index 0000000..7872e42 --- /dev/null +++ b/lib/libgfold/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "libgfold" +version = "0.1.0" +edition = "2021" + +# NOTE(nick): Temporary until libgfold is ready for release +publish = false + +# TODO(nick): add categories and description +authors = ["Nick Gerace <nickagerace@gmail.com>"] +homepage = "https://nickgerace.dev" +keywords = ["git"] +license = "Apache-2.0" +readme = "../../README.md" +repository = "https://github.com/nickgerace/gfold/" + +[dependencies] +anyhow = { version = "1.0", features = ["backtrace"] } +git2 = { version = "0.17", default_features = false } +log = "0.4" +rayon = "1.7" +serde = { version = "1.0", features = ["derive"] } +thiserror = "1.0" + +[dev-dependencies] +env_logger = { version = "0.10", features = ["humantime"], default_features = false } +pretty_assertions = "1.3" +tempfile = "3.5" diff --git a/crates/gfold/src/collector.rs b/lib/libgfold/src/collector.rs index c596dac..b80066e 100644 --- a/crates/gfold/src/collector.rs +++ b/lib/libgfold/src/collector.rs @@ -5,7 +5,6 @@ use std::collections::BTreeMap; use std::path::Path; use target::TargetCollector; -use crate::config::DisplayMode; use crate::repository_view::RepositoryView; mod target; @@ -24,16 +23,12 @@ type UnprocessedRepositoryView = anyhow::Result<RepositoryView>; pub struct RepositoryCollector; impl RepositoryCollector { - /// Generate [`RepositoryCollection`] for a given path and its children. The [`DisplayMode`] is - /// required because any two display modes can require differing amounts of data to be - /// collected. - pub fn run(path: &Path, display_mode: DisplayMode) -> anyhow::Result<RepositoryCollection> { - let (include_email, include_submodules) = match display_mode { - DisplayMode::Classic => (false, false), - DisplayMode::Json => (true, true), - DisplayMode::Standard => (true, false), - }; - + /// Generate [`RepositoryCollection`] for a given path and its children. + pub fn run( + path: &Path, + include_email: bool, + include_submodules: bool, + ) -> anyhow::Result<RepositoryCollection> { let unprocessed = TargetCollector::run(path.to_path_buf())? .par_iter() .map(|path| RepositoryView::new(path, include_email, include_submodules)) diff --git a/crates/gfold/src/collector/target.rs b/lib/libgfold/src/collector/target.rs index f13219d..f13219d 100644 --- a/crates/gfold/src/collector/target.rs +++ b/lib/libgfold/src/collector/target.rs diff --git a/crates/gfold/src/main.rs b/lib/libgfold/src/lib.rs index 47175b5..ed69670 100644 --- a/crates/gfold/src/main.rs +++ b/lib/libgfold/src/lib.rs @@ -1,38 +1,13 @@ -//! [gfold](https://github.com/nickgerace/gfold) is a CLI-driven application that helps you keep -//! track of multiple Git repositories. The source code uses private modules rather than leveraging -//! a library via `lib.rs`. +// #![warn(missing_docs, clippy::missing_errors_doc, clippy::missing_panics_doc)] -#![warn(missing_docs, clippy::missing_errors_doc, clippy::missing_panics_doc)] +pub mod collector; +pub mod repository_view; +pub mod status; -use env_logger::Builder; -use log::debug; -use log::LevelFilter; -use std::env; - -use crate::cli::CliHarness; - -mod cli; -mod collector; -mod config; -mod display; -mod repository_view; -mod run; -mod status; - -/// Initializes the logger based on the debug flag and `RUST_LOG` environment variable and uses -/// the [`CliHarness`] to generate a [`Config`](config::Config). Then, this calls -/// [`CliHarness::run()`]. -fn main() -> anyhow::Result<()> { - match env::var("RUST_LOG").is_err() { - true => Builder::new().filter_level(LevelFilter::Off).init(), - false => env_logger::init(), - } - debug!("initialized logger"); - - let cli_harness = CliHarness::new(); - cli_harness.run()?; - Ok(()) -} +pub use collector::RepositoryCollection; +pub use collector::RepositoryCollector; +pub use repository_view::RepositoryView; +pub use status::Status; #[cfg(test)] mod tests { @@ -43,22 +18,18 @@ mod tests { use git2::Oid; use git2::Repository; use git2::Signature; + use log::LevelFilter; use pretty_assertions::assert_eq; use std::fs::File; use std::path::{Path, PathBuf}; use std::{fs, io}; use tempfile::tempdir; - use crate::collector::{RepositoryCollection, RepositoryCollector}; - use crate::config::{Config, DisplayMode}; - use crate::repository_view::RepositoryView; - use crate::status::Status; - /// This integration test for `gfold` covers an end-to-end usage scenario. It uses the /// [`tempfile`](tempfile) crate to create some repositories with varying states and levels /// of nesting. #[test] - fn integration() -> anyhow::Result<()> { + fn poop() -> anyhow::Result<()> { env_logger::builder() .is_test(true) .filter_level(LevelFilter::Info) @@ -207,11 +178,8 @@ mod tests { nested_expected_views_raw.sort_by(|a, b| a.name.cmp(&b.name)); expected_collection.insert(Some(nested_expected_views_key), nested_expected_views_raw); - // Generate a collection. Use classic display mode to avoid collecting email results. - let mut config = Config::try_config_default()?; - config.path = root.path().to_path_buf(); - config.display_mode = DisplayMode::Classic; - let found_collection = RepositoryCollector::run(&config.path, config.display_mode)?; + // Generate a collection. + let found_collection = RepositoryCollector::run(root.path(), false, false)?; // Ensure the found collection matches our expected one. Sort the collection for the // assertion. diff --git a/crates/gfold/src/repository_view.rs b/lib/libgfold/src/repository_view.rs index fce5b47..64cf3f3 100644 --- a/crates/gfold/src/repository_view.rs +++ b/lib/libgfold/src/repository_view.rs @@ -36,12 +36,7 @@ pub struct RepositoryView { /// The remote origin URL. The value will be `None` if the URL cannot be found. pub url: Option<String>, - /// The "user.email" of a Git config that's only collected when using - /// [`DisplayMode::Standard`](crate::config::DisplayMode::Standard) - /// and [`DisplayMode::Json`](crate::config::DisplayMode::Json). pub email: Option<String>, - /// The submodules of a repository_view that are only collected when using - /// [`DisplayMode::Json`](crate::config::DisplayMode::Json). pub submodules: Vec<SubmoduleView>, } diff --git a/crates/gfold/src/repository_view/submodule_view.rs b/lib/libgfold/src/repository_view/submodule_view.rs index 54f0502..54f0502 100644 --- a/crates/gfold/src/repository_view/submodule_view.rs +++ b/lib/libgfold/src/repository_view/submodule_view.rs diff --git a/crates/gfold/src/status.rs b/lib/libgfold/src/status.rs index e6e104a..e6e104a 100644 --- a/crates/gfold/src/status.rs +++ b/lib/libgfold/src/status.rs |