8 个重大版本发布

0.12.0 2024年4月10日
0.10.0 2024年1月14日
0.9.4 2023年9月16日
0.6.1 2023年7月24日

751命令行工具 中排名

Download history 4/week @ 2024-04-27 1/week @ 2024-05-04 2/week @ 2024-05-18 7/week @ 2024-05-25 11/week @ 2024-06-01 2/week @ 2024-06-08 2/week @ 2024-06-15 3/week @ 2024-06-22 21/week @ 2024-06-29 227/week @ 2024-07-06 315/week @ 2024-07-27 2/week @ 2024-08-03

每月317 次下载
dedoc 中使用

MIT 许可证

45KB
1K SLoC

toiletcli

命令行应用程序框架,包括命令行参数解析器。

每个模块的文档中可以找到完整的概述。

可以通过功能启用/禁用模块

[features]
default = ["flags", "colors", "escapes"]

示例

//! Command line argument parsing.

use std::env::args;

use toiletcli::flags;
use toiletcli::flags::{FlagType, parse_flags, parse_flags_until_subcommand};

let mut args = args();

// Most often, path to the program will be the first argument.
// This will prevent the function from parsing, as path to the program does not start with '-'.
let program_name = args.next().unwrap();

let mut v_flag;

let mut main_flags = flags![
    v_flag: BoolFlag, ["-v", "--long-v"]
];

let subcommand = parse_flags_until_subcommand(&mut args, &mut main_flags).unwrap();

let mut d_flag;

let mut sub_flags = flags![
    d_flag: BoolFlag, ["-d"]
];

let subcommand_args = parse_flags(&mut args, &mut sub_flags);
//! Convenient ANSI terminal colors and styles.

use toiletcli::colors::{Color, Style, UnderlineStyle, StyleBuilder};

println!("{}{}This is red text on blue background!{}",
         Color::Red, Color::Blue.bg(), Style::Reset);

let weird_style = StyleBuilder::new()
    .foreground(Color::Byte(93))
    .background(Color::from_str("black").unwrap())
    .add_style(Style::Underlined)
    .underline_color(Color::RGB(0, 255, 0))
    .underline_style(UnderlineStyle::Curly)
    .build();

println!("{}RGB purple on black background with RGB curly green underline!{}",
        weird_style, Style::Reset);
//! Most common escapes to manipulate terminals.

use toiletcli::escapes::{Cursor, System};

println!("This is a 'word' that will be replaced!{}bird", Cursor::Position(12));
// This is a 'bird' that will be replaced!

println!("This is a '{}dog' that will be replaced too!{}cat", Cursor::Save, Cursor::Restore);
// This is a 'cat' that will be replaced too!

print!("{}", System::SetTitle("hello"));
// Look at the title :3
//! Common functions.

use toiletcli::common::{name_from_path};

let path = "toilet/bin/program";
let name = common::name_from_path(path);

assert_eq!(name, "program");

依赖项

~225KB