Skip to content

Commit

Permalink
split plumbing into separate binary
Browse files Browse the repository at this point in the history
This also has the advantage of possibly being smaller, as there is
less code to be included.
  • Loading branch information
Byron committed Jun 30, 2020
1 parent 0fbba9f commit b1e51d6
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 49 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/plumbing-cli.rs
Original file line number Diff line number Diff line change
@@ -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()
}
40 changes: 40 additions & 0 deletions src/plumbing/lean.rs
Original file line number Diff line number Diff line change
@@ -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())
}
}
}
5 changes: 5 additions & 0 deletions src/plumbing/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[cfg(feature = "pretty-cli")]
pub mod pretty;

#[cfg(all(feature = "lean-cli", not(feature = "pretty-cli")))]
pub mod lean;
40 changes: 40 additions & 0 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
15 changes: 0 additions & 15 deletions src/porcelain/lean.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod options {
use argh::FromArgs;
use std::path::PathBuf;

#[derive(FromArgs)]
/// A simple calculation tool
Expand All @@ -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())
}
}
}
26 changes: 1 addition & 25 deletions src/porcelain/pretty.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -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),
}
}

Expand All @@ -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(())
}
5 changes: 3 additions & 2 deletions tests/stateless-journey.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
}
)
)
Expand Down

0 comments on commit b1e51d6

Please sign in to comment.