Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ cargo clippy --all-targets -- -D warnings

When the user asks to run clippy and provides the ability to run on both targets, try to run it
on both targets.

## Formatting

After modifying code, run `cargo fmt` to ensure consistent formatting before committing changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ OPTIONS:
--timeout <SECONDS> Timeout for command execution
-v, --verbose Increase verbosity (-vvv for max)
-h, --help Print help
-V, --version Print version
-V, --version Print version with commit hash

RULE FORMAT:
Rules are specified with -r/--rule and use the format:
Expand Down
28 changes: 28 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::env;
use std::process::Command;

fn main() {
// Retrieve crate version provided by Cargo
let version = env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "unknown".to_string());

// Try to get short commit hash
let git_hash = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|o| {
if o.status.success() {
Some(String::from_utf8_lossy(&o.stdout).trim().to_string())
} else {
None
}
})
.unwrap_or_else(|| "unknown".to_string());

// Export as environment variables for use in the code and tests
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
println!(
"cargo:rustc-env=VERSION_WITH_GIT_HASH={} ({})",
version, git_hash
);
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tracing::{debug, info, warn};

#[derive(Parser, Debug)]
#[command(name = "httpjail")]
#[command(version, about, long_about = None)]
#[command(version = env!("VERSION_WITH_GIT_HASH"), about, long_about = None)]
#[command(about = "Monitor and restrict HTTP/HTTPS requests from processes")]
struct Args {
/// Rules for filtering requests (can be specified multiple times)
Expand Down
4 changes: 2 additions & 2 deletions tests/smoke_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ fn test_httpjail_help() {
fn test_httpjail_version() {
let mut cmd = Command::cargo_bin("httpjail").unwrap();
cmd.arg("--version");

let hash = env!("GIT_HASH");
cmd.assert()
.success()
.stdout(predicate::str::contains("httpjail"));
.stdout(predicate::str::contains("httpjail").and(predicate::str::contains(hash)));
}

#[test]
Expand Down