toiletcli

A framework for command line applications, including a command line argument parser.

Complete overview can be found in the documentation for each module.

Modules can be disabled/enabled via features: toml [features] default = ["flags", "colors", "escapes"]

Examples

```rust //! Command line argument parsing.

use std::env::args;

use toiletcli::flags; use toiletcli::flags::{FlagType, parseflags, parseflagsuntilsubcommand};

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 mainflags = flags![ vflag: BoolFlag, ["-v", "--long-v"] ];

let subcommand = parseflagsuntilsubcommand(&mut args, &mut mainflags).unwrap();

let mut d_flag;

let mut subflags = flags![ dflag: BoolFlag, ["-d"] ];

let subcommandargs = parseflags(&mut args, &mut sub_flags); ```

```rust //! 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 weirdstyle = StyleBuilder::new() .foreground(Color::Byte(93)) .background(Color::fromstr("black").unwrap()) .addstyle(Style::Underlined) .underlinecolor(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); ```

```rust //! 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 ```

```rust //! Common functions.

use toiletcli::common::{namefrompath};

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

assert_eq!(name, "program"); ```