Skip to main content

rapx/
help.rs

1use clap::builder::{
2    Styles,
3    styling::{Effects, Style},
4};
5
6pub const RAPX_AFTER_HELP: &str = color_print::cstr!(
7    r#"<bold>NOTE:</bold> multiple detections can be processed in single run by 
8appending the options to the arguments. Like `cargo rapx -f -m`
9will perform two kinds of detection in a row.
10
11<underline>Examples:</underline>
12
131. detect use-after-free and memory leak for a riscv target:
14   cargo rapx check -f -m -- --target riscv64gc-unknown-none-elf
152. detect use-after-free and memory leak for tests:
16   cargo rapx check -f -m -- --tests
173. detect use-after-free and memory leak for all members:
18   cargo rapx check -f -m -- --workspace
19
20<underline>Environment Variables (Values are case insensitive):</underline>
21
22    RAPX_LOG          verbosity of logging: trace, debug, info, warn
23                     trace: print all the detailed RAPx execution traces.
24                     debug: display intermediate analysis results.
25                     warn: show bugs detected only.
26                     RAPX_LOG supports both global and module level settings. For example:
27                     * Global level: `RAPX_LOG=TRACE`
28                     * Module level: `RAPX_LOG=some::module:DEBUG`
29                     * Mixed: `RAPX_LOG=TRACE,some::module:INFO,other::module:DEBUG`
30
31    RAPX_CLEAN        run cargo clean before check: true, false
32                      * true is the default value except that false is set
33
34    RAPX_RECURSIVE    scope of packages to check: none, shallow, deep
35                     * none or the variable not set: check for current folder
36                     * shallow: check for current workpace members
37                     * deep: check for all workspaces from current folder
38                      
39                     NOTE: for shallow or deep, rapx will enter each member
40                     folder to do the check.
41"#
42);
43
44pub const RAPX_VERSION: &str = concat!(
45    "version ",
46    env!("CARGO_PKG_VERSION"),
47    "\n",
48    "developed by ",
49    env!("CARGO_PKG_AUTHORS"),
50);
51
52pub const RAPX_STYLING: Styles = clap_cargo::style::CLAP_STYLING;
53
54pub fn styled_str(s: &str, style: &Style, bold: bool) -> String {
55    let style = if bold {
56        // clap_cargo::style::LITERAL
57        style.effects(Effects::BOLD)
58    } else {
59        *style
60    };
61    format!("\x1b[{}{}\x1b[0m", style.render(), s)
62}
63
64pub fn styled_cargo_rapx_usage() -> String {
65    let style = RAPX_STYLING.get_literal();
66    format!(
67        "{} {}",
68        styled_str("cargo rapx", style, true),
69        styled_str("[OPTIONS] <COMMAND> [-- [CARGO_FLAGS]]", style, false)
70    )
71}
72
73pub fn styled_rapx_usage() -> String {
74    let style = RAPX_STYLING.get_literal();
75    format!(
76        "{} {} {}",
77        styled_str("RAPXFLAGS=\"[OPTIONS] <COMMAND>\"", style, false),
78        styled_str("rapx", style, true),
79        styled_str("[RUSTFLAGS]", style, false)
80    )
81}