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