Skip to content

Commit

Permalink
chore(cli): improve documentation for scan command.
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed May 6, 2024
1 parent e8d158f commit 24a70bb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cli/src/commands/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ use crate::{help, walk};
pub fn scan() -> Command {
super::command("scan")
.about("Scan a file or directory")
.long_about(help::SCAN_LONG_HELP)
.arg(
arg!(<RULES_PATH>)
.help("Path to YARA source file")
.help("Path to a YARA source file or directory")
.value_parser(value_parser!(PathBuf))
.action(ArgAction::Append)
)
.arg(
arg!(<PATH>)
arg!(<TARGET_PATH>)
.help("Path to the file or directory that will be scanned")
.value_parser(value_parser!(PathBuf))
)
Expand Down Expand Up @@ -94,7 +95,7 @@ pub fn scan() -> Command {

pub fn exec_scan(args: &ArgMatches) -> anyhow::Result<()> {
let mut rules_path = args.get_many::<PathBuf>("RULES_PATH").unwrap();
let path = args.get_one::<PathBuf>("PATH").unwrap();
let target_path = args.get_one::<PathBuf>("TARGET_PATH").unwrap();
let compiled_rules = args.get_flag("compiled-rules");
let num_threads = args.get_one::<u8>("threads");
let path_as_namespace = args.get_flag("path-as-namespace");
Expand Down Expand Up @@ -162,7 +163,7 @@ pub fn exec_scan(args: &ArgMatches) -> anyhow::Result<()> {
let state = ScanState::new(start_time);

w.walk(
path,
target_path,
state,
// Initialization
|_, output| {
Expand Down
14 changes: 14 additions & 0 deletions cli/src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,17 @@ Examples:
yr completion bash > $(brew --prefix)/etc/bash_completion.d/yr
yr completion zsh > "${fpath[1]}/_kubectl"
"#;

pub const SCAN_LONG_HELP: &str = r#"Scan a file or directory
<RULES_PATH> can be the path to a file containing YARA rules, or the path to a directory
containing *.yar or *.yara files. When <RULES_PATH> is a directory, it will be traversed
recursively looking for rule files. Multiple <RULES_PATH> can be specified.
<TARGET_PATH> is the file or directory that will be scanned.
Examples:
yr scan rules_file.yar scanned_file
yr scan rules_dir scanned_file
"#;

0 comments on commit 24a70bb

Please sign in to comment.