Skip to main content

Crate velvetio

Crate velvetio 

Source
Expand description

§VelvetIO - Simple CLI Input for Rust

Getting user input in Rust CLI apps is annoying. VelvetIO makes it simple.

use velvetio::prelude::*;

let name = ask!("What's your name?");
let age = ask!("How old are you?" => u32);

if confirm!("Do you like Rust?") {
    println!("Great choice, {}!", name);
}

For complex input, use forms:

use velvetio::prelude::*;

let user_data = form()
    .text("name", "Full name")
    .number("age", "Age")
    .choice("role", "Role", &["User", "Admin"])
    .collect();

Modules§

prelude

Macros§

ask
Main macro for getting input
choose
confirm
multi_select
quick_form
Quick form macro for simple cases
quick_parse
Add Parse impl for types that have FromStr
try_ask

Structs§

VelvetIOError
Error type for VelvetIO operations

Traits§

Parse
Parse strings into Rust types

Functions§

and
Both validators must pass
ask
Keep asking until we get valid input
ask_with_default
Ask with default - hit enter to use default
ask_with_validation
Ask with validation function
choose
Pick one option from a list
confirm
Yes/no question
form
in_range
Number is within range (inclusive)
is_positive
Number is positive (> 0)
max_length
String has at most max characters
min_length
String has at least min characters
multi_select
Pick multiple options from a list
not_empty
String is not empty after trimming
or
Either validator can pass
try_ask
Try once, return Result instead of retrying

Type Aliases§

Result