Skip to main content

cxx2flow_lib/
cli.rs

1use clap::Parser;
2use std::sync::LazyLock;
3
4static NONE: &str = "None";
5static LONG_VERSION: LazyLock<String> = LazyLock::new(|| {
6    format!(
7        "
8Version:             {}
9Build Timestamp:     {}
10Build Git Describe:  {}
11Commit SHA:          {}
12Commit Date:         {}
13Commit Branch:       {}
14Cargo Target Triple: {}
15",
16        env!("CARGO_PKG_VERSION"),
17        env!("VERGEN_BUILD_TIMESTAMP"),
18        env!("VERGEN_GIT_DESCRIBE"),
19        option_env!("VERGEN_GIT_SHA").unwrap_or(NONE),
20        option_env!("VERGEN_GIT_COMMIT_TIMESTAMP").unwrap_or(NONE),
21        option_env!("VERGEN_GIT_BRANCH").unwrap_or(NONE),
22        env!("VERGEN_CARGO_TARGET_TRIPLE"),
23    )
24});
25#[derive(Parser, Debug)]
26#[clap(about, version, long_version(LONG_VERSION.as_str()) ,author, after_help("Note that you need to manually compile the dot file using graphviz to get SVG or PNG files.
27
28EXAMPLES:
29    cat main.cpp | cxx2flow | dot -Tsvg -o test.svg
30    cxx2flow test.cpp | dot -Tpng -o test.png
31    cxx2flow main.cpp my_custom_func | dot -Tsvg -o test.svg
32
33Please give me star if this application helps you!
34如果这个应用有帮助到你,请给我点一个 star!
35https://github.com/Enter-tainer/cxx2flow
36"))]
37pub struct Args {
38    #[clap(
39        short,
40        long,
41        help(
42            "Sets the output file.
43If not specified, result will be directed to stdout.
44e.g. graph.dot"
45        )
46    )]
47    pub output: Option<String>,
48
49    #[clap(
50        short,
51        long,
52        help(
53            "Sets the style of the flow chart.
54If specified, output flow chart will have curly connection line."
55        )
56    )]
57    pub curly: bool,
58
59    #[clap(long, help("Use C preprocessor."))]
60    pub cpp: bool,
61
62    #[clap(short, long, help("Use tikz backend."))]
63    pub tikz: bool,
64
65    #[clap(short, long, help("Use d2 backend."))]
66    pub d2: bool,
67
68    #[clap(long, help("Dump AST(For debug purpose only)."))]
69    pub dump_ast: bool,
70
71    #[clap(help(
72        "Sets the path of the input file. e.g. test.cpp
73If not specified, cxx2flow will read from stdin."
74    ))]
75    pub input: Option<String>,
76
77    #[clap(
78        default_value("main"),
79        help("The function you want to convert. e.g. main")
80    )]
81    pub function: String,
82}