Skip to content

Commit c7759f8

Browse files
committed
refactor(cli): change the way in which the output path is passed to the compile command
The output path was passed as the last positional argument for the command, but this have an inconvenience. If the user pass multiple input files and forgets to specify an output path, the last input path is used as output and the input file is overwritten. In order to prevent this, the output path is now passed with the `--output` option. If the option is missing, the default path `output.yarc` is used. Closes #126.
1 parent 5a70903 commit c7759f8

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

cli/src/commands/compile.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,10 @@ pub fn compile() -> Command {
1717
.action(ArgAction::Append),
1818
)
1919
.arg(
20-
arg!(<OUTPUT_PATH>)
21-
.help("Path to file with compiled results")
22-
.value_parser(value_parser!(PathBuf)),
23-
)
24-
.arg(
25-
arg!(--"path-as-namespace")
26-
.help("Use file path as rule namespace"),
27-
)
28-
.arg(
29-
arg!(--"relaxed-re-syntax")
30-
.help("Use a more relaxed syntax check while parsing regular expressions"),
20+
arg!(-o --"output" <OUTPUT_PATH>)
21+
.help("Output file with compiled results")
22+
.default_value("output.yarc")
23+
.value_parser(value_parser!(PathBuf))
3124
)
3225
.arg(
3326
Arg::new("define")
@@ -40,12 +33,20 @@ pub fn compile() -> Command {
4033
.value_parser(external_var_parser)
4134
.action(ArgAction::Append),
4235
)
36+
.arg(
37+
arg!(--"path-as-namespace")
38+
.help("Use file path as rule namespace"),
39+
)
40+
.arg(
41+
arg!(--"relaxed-re-syntax")
42+
.help("Use a more relaxed syntax check while parsing regular expressions"),
43+
)
4344
}
4445

4546
pub fn exec_compile(args: &ArgMatches) -> anyhow::Result<()> {
4647
let rules_path = args.get_many::<PathBuf>("RULES_PATH").unwrap();
47-
let output_path = args.get_one::<PathBuf>("OUTPUT_PATH").unwrap();
4848
let path_as_namespace = args.get_flag("path-as-namespace");
49+
let output_path = args.get_one::<PathBuf>("output").unwrap();
4950

5051
let external_vars: Option<Vec<(String, serde_json::Value)>> = args
5152
.get_many::<(String, serde_json::Value)>("define")

site/content/docs/intro/cli.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,17 @@ re-used for multiple scan operations.
160160
The syntax for this command is:
161161

162162
```
163-
yr compile [OPTIONS] <RULES_PATH>... <OUTPUT_PATH>
163+
yr compile [OPTIONS] <RULES_PATH>...
164164
```
165165

166166
Each `<RULES_PATH>` is the path of YARA source file or a directory containing
167167
source files. When`<RULES_PATH>` is a directory YARA-X iterates the directory
168168
recursively looking for any `*.yar` or `*.yara` files.
169169

170-
The `<OUTPUT_PATH>` is the path of the output binary file. The supported
171-
options are:
170+
### --output, -o <OUTPUT_PATH>
171+
172+
Specify the path for the output binary file containing the compiled rules. By
173+
default, is `output.yarc`.
172174

173175
### --relaxed-re-syntax
174176

0 commit comments

Comments
 (0)