2 个版本

0.1.1 2023 年 11 月 9 日
0.1.0 2023 年 1 月 14 日

5#pomsky

每月 23 次下载
pomsky-bin 中使用

MIT/Apache

295KB
341

helptext

文档

Rust 宏,用于打印漂亮的帮助信息。

Short help

Long help


lib.rs:

一个用于打印漂亮帮助信息的库。

use helptext::{Help, sections};

const HELP: Help = Help(sections!(
    ["my-cool-program " {env!("CARGO_PKG_VERSION")}]
    ["Use " c:"-h" " for short descriptions and " c:"--help" " for more details."]
    []
    "USAGE" {
        ["my-cool-program [OPTIONS] <INPUT>"]
    }
    "OPTIONS" {
        table Auto {
            "-h, --help" => {
                ["Print help information"]
                Long ["Use " c:"-h" " for short descriptions and " c:"--help" " for more details."]
            }
            "-p, --path <FILE>" => {
                ["File containing the pomsky expression to compile"]
            }
            "-V, --version" => {
                ["Print version information"]
            }
            "-W, --warnings <DIAGNOSTICS>" => {
                Short ["Disable certain warnings (disable all with " c:"-W0" ")"]
                Long ["Disable some or all warnings. A single warning can be disabled by specifying
the name followed by " c:"=0" ", for example:

    " c!"-Wcompat=0" "

Multiple warnings can be disabled by setting this option multiple times, or
using a comma-separated list:

    " c!"-Wcompat=0 -Wdeprecated=0
    -Wcompat=0,deprecated=0" "

To disable all warnings, use " c:"-W0" ".

Currently, the following warnings can be disabled:"]
                Long table Compact {
                    "compat"     => { ["Compatibility warnings"] }
                    "deprecated" => { ["A used feature will be removed in the future"] }
                }
            }
        }
    }
));

fn print_short_help(use_colors: bool) {
    HELP.write(
        &mut std::io::stdout().lock(),
        false,  // don't show long help
        use_colors,
    );
}

fn print_long_help(use_colors: bool) {
    HELP.write(
        &mut std::io::stdout().lock(),
        true,  // show long help
        use_colors,
    );
}

结果

Short help

Long help

无运行时依赖