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    RAP_LOG          verbosity of logging: trace, debug, info, warn
23                     trace: print all the detailed RAP execution traces.
24                     debug: display intermediate analysis results.
25                     warn: show bugs detected only.
26
27    RAP_CLEAN        run cargo clean before check: true, false
28                     * true is the default value except that false is set
29
30    RAP_RECURSIVE    scope of packages to check: none, shallow, deep
31                     * none or the variable not set: check for current folder
32                     * shallow: check for current workpace members
33                     * deep: check for all workspaces from current folder
34                      
35                     NOTE: for shallow or deep, rapx will enter each member
36                     folder to do the check.
37"#
38);
39
40pub const RAPX_VERSION: &str = concat!(
41    "version ",
42    env!("CARGO_PKG_VERSION"),
43    "\n",
44    "developed by ",
45    env!("CARGO_PKG_AUTHORS"),
46);
47
48pub const CARGO_RAPX_STYLING: Styles = clap_cargo::style::CLAP_STYLING;
49pub const RAPX_STYLING: Styles = clap_cargo::style::CLAP_STYLING;
50
51pub fn styled_str(s: &str, style: &Style, bold: bool) -> String {
52    let style = if bold {
53        // clap_cargo::style::LITERAL
54        style.effects(Effects::BOLD)
55    } else {
56        *style
57    };
58    format!("\x1b[{}{}\x1b[0m", style.render(), s)
59}
60
61pub fn styled_cargo_rapx_usage() -> String {
62    let style = CARGO_RAPX_STYLING.get_literal();
63    format!(
64        "{} {}",
65        styled_str("cargo rapx", &style, true),
66        styled_str("[OPTIONS] <COMMAND> [-- [CARGO_FLAGS]]", &style, false)
67    )
68}
69
70pub fn styled_rapx_usage() -> String {
71    let style = RAPX_STYLING.get_literal();
72    format!(
73        "{} {} {}",
74        styled_str("RAPFLAGS=\"[OPTIONS] <COMMAND>\"", &style, false),
75        styled_str("rapx", &style, true),
76        styled_str("[RUSTFLAGS]", &style, false)
77    )
78}