diff --git a/Cargo.toml b/Cargo.toml index 79d0985bb11..f1809a816b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,12 @@ path="src/porcelain-cli.rs" test = false doctest = false +[[bin]] +name="gio-plumbing" +path="src/plumbing-cli.rs" +test = false +doctest = false + [features] default = ["fast", "pretty-cli"] fast = ["git-features/parallel", "git-features/fast-sha1"] diff --git a/Makefile b/Makefile index 6f5ec6aa511..47efc0cd4c9 100644 --- a/Makefile +++ b/Makefile @@ -13,11 +13,8 @@ interactive-developer-environment-in-docker: ## Use docker for all dependencies ##@ Development -target/debug/gio: always - cargo build --no-default-features --features pretty-cli - target/release/gio: always - cargo build --release + cargo build --release --no-default-features --features lean-cli lint: ## Run lints with clippy cargo clippy @@ -33,6 +30,10 @@ tests: check unit-tests journey-tests journey-tests-lean-cli ## run all tests, i check: ## Build all code in suitable configurations cargo check --all + cargo check --all --all-features + cargo check --no-default-features --features lean-cli + cargo check --no-default-features --features pretty-cli + cargo check --no-default-features --features lean-cli,fast cd git-features && cargo check --all-features \ && cargo check --features parallel \ && cargo check --features fast-sha1 @@ -43,12 +44,13 @@ unit-tests: ## run all unit tests continuous-unit-tests: ## run all unit tests whenever something changes watchexec -w src $(MAKE) unit-tests -journey-tests: target/debug/gio ## run stateless journey tests (pretty-cli) - ./tests/stateless-journey.sh $< +journey-tests: always ## run stateless journey tests (pretty-cli) + cargo build + ./tests/stateless-journey.sh target/debug/gio target/debug/gio-plumbing journey-tests-lean-cli: always ## run stateless journey tests (lean-cli) cargo build --no-default-features --features lean-cli - ./tests/stateless-journey.sh target/debug/gio + ./tests/stateless-journey.sh target/debug/gio target/debug/gio-plumbing continuous-journey-tests: ## run stateless journey tests whenever something changes watchexec $(MAKE) journey-tests diff --git a/src/plumbing-cli.rs b/src/plumbing-cli.rs new file mode 100644 index 00000000000..c55db842d4f --- /dev/null +++ b/src/plumbing-cli.rs @@ -0,0 +1,15 @@ +#![forbid(unsafe_code)] + +mod plumbing; + +use anyhow::Result; + +#[cfg(feature = "pretty-cli")] +fn main() -> Result<()> { + plumbing::pretty::main() +} + +#[cfg(all(feature = "lean-cli", not(feature = "pretty-cli")))] +fn main() -> Result<()> { + plumbing::lean::main() +} diff --git a/src/plumbing/lean.rs b/src/plumbing/lean.rs new file mode 100644 index 00000000000..8e9cffe30f2 --- /dev/null +++ b/src/plumbing/lean.rs @@ -0,0 +1,40 @@ +mod options { + use argh::FromArgs; + use std::path::PathBuf; + + #[derive(FromArgs)] + /// A simple calculation tool + pub struct Args { + #[argh(subcommand)] + pub subcommand: SubCommands, + } + + #[derive(FromArgs, PartialEq, Debug)] + #[argh(subcommand)] + pub enum SubCommands { + VerifyPack(VerifyPack), + } + + /// Initialize the repository in the current directory. + #[derive(FromArgs, PartialEq, Debug)] + #[argh(subcommand, name = "verify-pack")] + pub struct VerifyPack { + /// the '.pack' or '.idx' file whose checksum to validate. + #[argh(positional)] + pub path: PathBuf, + } +} + +use anyhow::Result; +use gitoxide_core as core; +use std::io::{stderr, stdout}; + +pub fn main() -> Result<()> { + pub use options::*; + let cli: Args = argh::from_env(); + match cli.subcommand { + SubCommands::VerifyPack(VerifyPack { path }) => { + core::verify_pack_or_pack_index(path, stdout(), stderr()) + } + } +} diff --git a/src/plumbing/mod.rs b/src/plumbing/mod.rs new file mode 100644 index 00000000000..86c6d20d2d3 --- /dev/null +++ b/src/plumbing/mod.rs @@ -0,0 +1,5 @@ +#[cfg(feature = "pretty-cli")] +pub mod pretty; + +#[cfg(all(feature = "lean-cli", not(feature = "pretty-cli")))] +pub mod lean; diff --git a/src/plumbing/pretty.rs b/src/plumbing/pretty.rs new file mode 100644 index 00000000000..92c6ee25942 --- /dev/null +++ b/src/plumbing/pretty.rs @@ -0,0 +1,40 @@ +use anyhow::Result; +use gitoxide_core as core; +use std::io::{stderr, stdout}; +use structopt::StructOpt; + +mod options { + use std::path::PathBuf; + use structopt::{clap::AppSettings, StructOpt}; + + #[derive(Debug, StructOpt)] + #[structopt(about = "The git, simply swift")] + #[structopt(settings = &[AppSettings::SubcommandRequired, + AppSettings::ColoredHelp])] + pub struct Args { + #[structopt(subcommand)] + pub cmd: Subcommands, + } + + #[derive(Debug, StructOpt)] + pub enum Subcommands { + /// Verify the integrity of a pack or index file + #[structopt(setting = AppSettings::ColoredHelp)] + VerifyPack { + /// The '.pack' or '.idx' file whose checksum to validate. + #[structopt(parse(from_os_str))] + path: PathBuf, + }, + } +} + +pub fn main() -> Result<()> { + use options::*; + let args = Args::from_args(); + match args.cmd { + Subcommands::VerifyPack { path } => { + core::verify_pack_or_pack_index(path, stdout(), stderr()) + } + }?; + Ok(()) +} diff --git a/src/porcelain/lean.rs b/src/porcelain/lean.rs index a67de0a2820..2c45af47598 100644 --- a/src/porcelain/lean.rs +++ b/src/porcelain/lean.rs @@ -1,6 +1,5 @@ mod options { use argh::FromArgs; - use std::path::PathBuf; #[derive(FromArgs)] /// A simple calculation tool @@ -13,35 +12,21 @@ mod options { #[argh(subcommand)] pub enum SubCommands { Init(Init), - VerifyPack(VerifyPack), } /// Initialize the repository in the current directory. #[derive(FromArgs, PartialEq, Debug)] #[argh(subcommand, name = "init")] pub struct Init {} - - /// Initialize the repository in the current directory. - #[derive(FromArgs, PartialEq, Debug)] - #[argh(subcommand, name = "verify-pack")] - pub struct VerifyPack { - /// the '.pack' or '.idx' file whose checksum to validate. - #[argh(option)] - pub path: PathBuf, - } } use anyhow::Result; use gitoxide_core as core; -use std::io::{stderr, stdout}; pub fn main() -> Result<()> { pub use options::*; let cli: Args = argh::from_env(); match cli.subcommand { SubCommands::Init(_) => core::init(), - SubCommands::VerifyPack(VerifyPack { path }) => { - core::verify_pack_or_pack_index(path, stdout(), stderr()) - } } } diff --git a/src/porcelain/pretty.rs b/src/porcelain/pretty.rs index 3ca5819d852..5c36a862eed 100644 --- a/src/porcelain/pretty.rs +++ b/src/porcelain/pretty.rs @@ -1,12 +1,9 @@ use anyhow::Result; use gitoxide_core as core; -use std::io::{stderr, stdout}; use structopt::StructOpt; mod options { - use std::path::PathBuf; - use structopt::clap::AppSettings; - use structopt::StructOpt; + use structopt::{clap::AppSettings, StructOpt}; #[derive(Debug, StructOpt)] #[structopt(about = "The git, simply swift")] @@ -17,28 +14,12 @@ mod options { pub cmd: Subcommands, } - /// Low-level commands that are not used every day - #[derive(Debug, StructOpt)] - pub enum Plumbing { - /// Verify the integrity of a pack or index file - #[structopt(setting = AppSettings::ColoredHelp)] - VerifyPack { - /// The '.pack' or '.idx' file whose checksum to validate. - #[structopt(parse(from_os_str))] - path: PathBuf, - }, - } - #[derive(Debug, StructOpt)] pub enum Subcommands { /// Initialize the repository in the current directory. #[structopt(alias = "initialize")] #[structopt(setting = AppSettings::ColoredHelp)] Init, - - #[structopt(alias = "p")] - #[structopt(setting = AppSettings::ColoredHelp)] - Plumbing(Plumbing), } } @@ -47,11 +28,6 @@ pub fn main() -> Result<()> { let args = Args::from_args(); match args.cmd { Subcommands::Init => core::init(), - Subcommands::Plumbing(cmd) => match cmd { - Plumbing::VerifyPack { path } => { - core::verify_pack_or_pack_index(path, stdout(), stderr()) - } - }, }?; Ok(()) } diff --git a/tests/stateless-journey.sh b/tests/stateless-journey.sh index af078f2a05e..9bb990d9bc1 100755 --- a/tests/stateless-journey.sh +++ b/tests/stateless-journey.sh @@ -2,6 +2,7 @@ set -eu exe=${1:?First argument must be the executable to test} +exe_plumbing=${2:?Second argument must be the plumbing executable to test} root="$(cd "${0%/*}" && pwd)" exe="${root}/../$exe" @@ -49,14 +50,14 @@ title "CLI" PACK_FILE="$fixtures/packs/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack" it "verifies the pack successfully and with desired output" && { WITH_SNAPSHOT="$snapshot/plumbing-verify-pack-success" \ - expect_run $SUCCESSFULLY "$exe" plumbing verify-pack "$PACK_FILE" + expect_run $SUCCESSFULLY "$exe_plumbing" verify-pack "$PACK_FILE" } ) (with "a valid pack file" PACK_INDEX_FILE="$fixtures/packs/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.idx" it "verifies the pack index successfully and with desired output" && { WITH_SNAPSHOT="$snapshot/plumbing-verify-pack-index-success" \ - expect_run $SUCCESSFULLY "$exe" plumbing verify-pack "$PACK_INDEX_FILE" + expect_run $SUCCESSFULLY "$exe_plumbing" verify-pack "$PACK_INDEX_FILE" } ) )