Skip to content

Commit

Permalink
make env var an option
Browse files Browse the repository at this point in the history
  • Loading branch information
hkctkuy committed Nov 3, 2023
1 parent f25507a commit ccf5c63
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion casr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exclude = ["/tests"]
[dependencies]
shell-words = "1.1"
anyhow = "1.0"
clap = { version = "4.2", features = ["wrap_help", "cargo"] }
clap = { version = "4.2", features = ["wrap_help", "cargo", "env"] }
chrono = "0.4"
goblin = "0.6"
log = "0.4"
Expand Down
16 changes: 10 additions & 6 deletions casr/src/bin/casr-cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use casr::util;
use libcasr::{init_ignored_frames, stacktrace::*};

use anyhow::{bail, Context, Result};
use clap::{Arg, ArgAction};
use clap::{builder::FalseyValueParser, Arg, ArgAction};
use rayon::iter::{IndexedParallelIterator, ParallelIterator};
use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator};

Expand Down Expand Up @@ -365,6 +365,14 @@ fn main() -> Result<()> {
reports in this directory will not be deleted.",
),
)
.arg(
Arg::new("cluster-unique-crashline")
.long("cluster-unique-crashline")
.env("CASR_CLUSTER_UNIQUE_CRASHLINE")
.action(ArgAction::SetTrue)
.value_parser(FalseyValueParser::new())
.help("Deduplicate each cluster by crashline")
)
.arg(
Arg::new("deduplication")
.short('d')
Expand Down Expand Up @@ -426,11 +434,7 @@ fn main() -> Result<()> {
}

// Get env var
let dedup_crashlines = if let Ok(dedup) = std::env::var("CASR_CLUSTER_UNIQUE_CRASHLINE") {
dedup == "1"
} else {
false
};
let dedup_crashlines = matches.get_flag("cluster-unique-crashline");

if matches.contains_id("similarity") {
let casreps: Vec<&PathBuf> = matches.get_many::<PathBuf>("similarity").unwrap().collect();
Expand Down
7 changes: 5 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ Tool for clustering CASR reports
Cluster CASR reports. If two directories are set, clusters will be placed in the
second directory. If one directory is provided, clusters will be placed there,
but reports in this directory will not be deleted.
--cluster-unique-crashline
Deduplicate each cluster by crashline [env: CASR_CLUSTER_UNIQUE_CRASHLINE=]
-d, --deduplicate <INPUT_DIR> <OUTPUT_DIR>
Deduplicate CASR reports. If two directories are set, deduplicated reports are
copied to the second directory. If one directory is provided, duplicated reports
Expand Down Expand Up @@ -299,8 +301,9 @@ For the **--ignore <FILE>** option, file format should be as follows:
Headers may be in different order, one of them may be missing.
Frames that match these regular expressions will be not considered during analysis.

When `CASR_CLUSTER_UNIQUE_CRASHLINE` environment variable is set to 1, each
cluster will contain reports with unique crash lines.
For `CASR_CLUSTER_UNIQUE_CRASHLINE` a `false` literal is `n`, `no`, `f`,
`false`, `off` or `0`. An absent environment variable will also be considered as
`false`. Anything else will considered as true.

## casr-cli

Expand Down

0 comments on commit ccf5c63

Please sign in to comment.