Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1e51d6

Browse files
committed
split plumbing into separate binary
This also has the advantage of possibly being smaller, as there is less code to be included.
1 parent 0fbba9f commit b1e51d6

9 files changed

Lines changed: 119 additions & 49 deletions

File tree

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ path="src/porcelain-cli.rs"
1313
test = false
1414
doctest = false
1515

16+
[[bin]]
17+
name="gio-plumbing"
18+
path="src/plumbing-cli.rs"
19+
test = false
20+
doctest = false
21+
1622
[features]
1723
default = ["fast", "pretty-cli"]
1824
fast = ["git-features/parallel", "git-features/fast-sha1"]

Makefile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ interactive-developer-environment-in-docker: ## Use docker for all dependencies
1313

1414
##@ Development
1515

16-
target/debug/gio: always
17-
cargo build --no-default-features --features pretty-cli
18-
1916
target/release/gio: always
20-
cargo build --release
17+
cargo build --release --no-default-features --features lean-cli
2118

2219
lint: ## Run lints with clippy
2320
cargo clippy
@@ -33,6 +30,10 @@ tests: check unit-tests journey-tests journey-tests-lean-cli ## run all tests, i
3330

3431
check: ## Build all code in suitable configurations
3532
cargo check --all
33+
cargo check --all --all-features
34+
cargo check --no-default-features --features lean-cli
35+
cargo check --no-default-features --features pretty-cli
36+
cargo check --no-default-features --features lean-cli,fast
3637
cd git-features && cargo check --all-features \
3738
&& cargo check --features parallel \
3839
&& cargo check --features fast-sha1
@@ -43,12 +44,13 @@ unit-tests: ## run all unit tests
4344
continuous-unit-tests: ## run all unit tests whenever something changes
4445
watchexec -w src $(MAKE) unit-tests
4546

46-
journey-tests: target/debug/gio ## run stateless journey tests (pretty-cli)
47-
./tests/stateless-journey.sh $<
47+
journey-tests: always ## run stateless journey tests (pretty-cli)
48+
cargo build
49+
./tests/stateless-journey.sh target/debug/gio target/debug/gio-plumbing
4850

4951
journey-tests-lean-cli: always ## run stateless journey tests (lean-cli)
5052
cargo build --no-default-features --features lean-cli
51-
./tests/stateless-journey.sh target/debug/gio
53+
./tests/stateless-journey.sh target/debug/gio target/debug/gio-plumbing
5254

5355
continuous-journey-tests: ## run stateless journey tests whenever something changes
5456
watchexec $(MAKE) journey-tests

src/plumbing-cli.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![forbid(unsafe_code)]
2+
3+
mod plumbing;
4+
5+
use anyhow::Result;
6+
7+
#[cfg(feature = "pretty-cli")]
8+
fn main() -> Result<()> {
9+
plumbing::pretty::main()
10+
}
11+
12+
#[cfg(all(feature = "lean-cli", not(feature = "pretty-cli")))]
13+
fn main() -> Result<()> {
14+
plumbing::lean::main()
15+
}

src/plumbing/lean.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
mod options {
2+
use argh::FromArgs;
3+
use std::path::PathBuf;
4+
5+
#[derive(FromArgs)]
6+
/// A simple calculation tool
7+
pub struct Args {
8+
#[argh(subcommand)]
9+
pub subcommand: SubCommands,
10+
}
11+
12+
#[derive(FromArgs, PartialEq, Debug)]
13+
#[argh(subcommand)]
14+
pub enum SubCommands {
15+
VerifyPack(VerifyPack),
16+
}
17+
18+
/// Initialize the repository in the current directory.
19+
#[derive(FromArgs, PartialEq, Debug)]
20+
#[argh(subcommand, name = "verify-pack")]
21+
pub struct VerifyPack {
22+
/// the '.pack' or '.idx' file whose checksum to validate.
23+
#[argh(positional)]
24+
pub path: PathBuf,
25+
}
26+
}
27+
28+
use anyhow::Result;
29+
use gitoxide_core as core;
30+
use std::io::{stderr, stdout};
31+
32+
pub fn main() -> Result<()> {
33+
pub use options::*;
34+
let cli: Args = argh::from_env();
35+
match cli.subcommand {
36+
SubCommands::VerifyPack(VerifyPack { path }) => {
37+
core::verify_pack_or_pack_index(path, stdout(), stderr())
38+
}
39+
}
40+
}

src/plumbing/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[cfg(feature = "pretty-cli")]
2+
pub mod pretty;
3+
4+
#[cfg(all(feature = "lean-cli", not(feature = "pretty-cli")))]
5+
pub mod lean;

src/plumbing/pretty.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use anyhow::Result;
2+
use gitoxide_core as core;
3+
use std::io::{stderr, stdout};
4+
use structopt::StructOpt;
5+
6+
mod options {
7+
use std::path::PathBuf;
8+
use structopt::{clap::AppSettings, StructOpt};
9+
10+
#[derive(Debug, StructOpt)]
11+
#[structopt(about = "The git, simply swift")]
12+
#[structopt(settings = &[AppSettings::SubcommandRequired,
13+
AppSettings::ColoredHelp])]
14+
pub struct Args {
15+
#[structopt(subcommand)]
16+
pub cmd: Subcommands,
17+
}
18+
19+
#[derive(Debug, StructOpt)]
20+
pub enum Subcommands {
21+
/// Verify the integrity of a pack or index file
22+
#[structopt(setting = AppSettings::ColoredHelp)]
23+
VerifyPack {
24+
/// The '.pack' or '.idx' file whose checksum to validate.
25+
#[structopt(parse(from_os_str))]
26+
path: PathBuf,
27+
},
28+
}
29+
}
30+
31+
pub fn main() -> Result<()> {
32+
use options::*;
33+
let args = Args::from_args();
34+
match args.cmd {
35+
Subcommands::VerifyPack { path } => {
36+
core::verify_pack_or_pack_index(path, stdout(), stderr())
37+
}
38+
}?;
39+
Ok(())
40+
}

src/porcelain/lean.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
mod options {
22
use argh::FromArgs;
3-
use std::path::PathBuf;
43

54
#[derive(FromArgs)]
65
/// A simple calculation tool
@@ -13,35 +12,21 @@ mod options {
1312
#[argh(subcommand)]
1413
pub enum SubCommands {
1514
Init(Init),
16-
VerifyPack(VerifyPack),
1715
}
1816

1917
/// Initialize the repository in the current directory.
2018
#[derive(FromArgs, PartialEq, Debug)]
2119
#[argh(subcommand, name = "init")]
2220
pub struct Init {}
23-
24-
/// Initialize the repository in the current directory.
25-
#[derive(FromArgs, PartialEq, Debug)]
26-
#[argh(subcommand, name = "verify-pack")]
27-
pub struct VerifyPack {
28-
/// the '.pack' or '.idx' file whose checksum to validate.
29-
#[argh(option)]
30-
pub path: PathBuf,
31-
}
3221
}
3322

3423
use anyhow::Result;
3524
use gitoxide_core as core;
36-
use std::io::{stderr, stdout};
3725

3826
pub fn main() -> Result<()> {
3927
pub use options::*;
4028
let cli: Args = argh::from_env();
4129
match cli.subcommand {
4230
SubCommands::Init(_) => core::init(),
43-
SubCommands::VerifyPack(VerifyPack { path }) => {
44-
core::verify_pack_or_pack_index(path, stdout(), stderr())
45-
}
4631
}
4732
}

src/porcelain/pretty.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
use anyhow::Result;
22
use gitoxide_core as core;
3-
use std::io::{stderr, stdout};
43
use structopt::StructOpt;
54

65
mod options {
7-
use std::path::PathBuf;
8-
use structopt::clap::AppSettings;
9-
use structopt::StructOpt;
6+
use structopt::{clap::AppSettings, StructOpt};
107

118
#[derive(Debug, StructOpt)]
129
#[structopt(about = "The git, simply swift")]
@@ -17,28 +14,12 @@ mod options {
1714
pub cmd: Subcommands,
1815
}
1916

20-
/// Low-level commands that are not used every day
21-
#[derive(Debug, StructOpt)]
22-
pub enum Plumbing {
23-
/// Verify the integrity of a pack or index file
24-
#[structopt(setting = AppSettings::ColoredHelp)]
25-
VerifyPack {
26-
/// The '.pack' or '.idx' file whose checksum to validate.
27-
#[structopt(parse(from_os_str))]
28-
path: PathBuf,
29-
},
30-
}
31-
3217
#[derive(Debug, StructOpt)]
3318
pub enum Subcommands {
3419
/// Initialize the repository in the current directory.
3520
#[structopt(alias = "initialize")]
3621
#[structopt(setting = AppSettings::ColoredHelp)]
3722
Init,
38-
39-
#[structopt(alias = "p")]
40-
#[structopt(setting = AppSettings::ColoredHelp)]
41-
Plumbing(Plumbing),
4223
}
4324
}
4425

@@ -47,11 +28,6 @@ pub fn main() -> Result<()> {
4728
let args = Args::from_args();
4829
match args.cmd {
4930
Subcommands::Init => core::init(),
50-
Subcommands::Plumbing(cmd) => match cmd {
51-
Plumbing::VerifyPack { path } => {
52-
core::verify_pack_or_pack_index(path, stdout(), stderr())
53-
}
54-
},
5531
}?;
5632
Ok(())
5733
}

tests/stateless-journey.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -eu
33

44
exe=${1:?First argument must be the executable to test}
5+
exe_plumbing=${2:?Second argument must be the plumbing executable to test}
56

67
root="$(cd "${0%/*}" && pwd)"
78
exe="${root}/../$exe"
@@ -49,14 +50,14 @@ title "CLI"
4950
PACK_FILE="$fixtures/packs/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.pack"
5051
it "verifies the pack successfully and with desired output" && {
5152
WITH_SNAPSHOT="$snapshot/plumbing-verify-pack-success" \
52-
expect_run $SUCCESSFULLY "$exe" plumbing verify-pack "$PACK_FILE"
53+
expect_run $SUCCESSFULLY "$exe_plumbing" verify-pack "$PACK_FILE"
5354
}
5455
)
5556
(with "a valid pack file"
5657
PACK_INDEX_FILE="$fixtures/packs/pack-11fdfa9e156ab73caae3b6da867192221f2089c2.idx"
5758
it "verifies the pack index successfully and with desired output" && {
5859
WITH_SNAPSHOT="$snapshot/plumbing-verify-pack-index-success" \
59-
expect_run $SUCCESSFULLY "$exe" plumbing verify-pack "$PACK_INDEX_FILE"
60+
expect_run $SUCCESSFULLY "$exe_plumbing" verify-pack "$PACK_INDEX_FILE"
6061
}
6162
)
6263
)

0 commit comments

Comments
 (0)