ineed

Crates.ioineed
lib.rsineed
version0.1.1
created_at2025-05-15 19:16:08.456477+00
updated_at2025-05-17 12:46:53.323734+00
descriptionLightweight CLI prompting library
homepage
repositoryhttps://github.com/ahmadbky/ineed
max_upload_size
id1675560
size96,699
Ahmad (ahmadbky)

documentation

https://docs.rs/ineed

README

ineed

ineed is a lightweight CLI prompting Rust crate.

It provides utility traits and types to prompt values in a more convenient way, and allows you to customize the style of the prompts.

Usage

First, add the crate to your dependency:

cargo add ineed

Then, add this line at the beginning of your code:

use ineed::prelude::*;

You are ready to use this crate. If you need a written value of any type, let's say u8, you can just ask for it:

let age = ineed::written::<u8>("How old are you?").prompt().unwrap();

ineed will manage the prompt format for you, and the input checking.

This example prints something similar to this:

- How old are you?
>

Features

You want to customize the prompt? Use the .fmt(...) method like this:

let age = ineed::written::<u8>("How old are you?")
    .fmt(ineed::fmt().input_prefix(">> "))
    .prompt()
    .unwrap();
println!("You are {age}!");

And the last line will be >> instead of > from the previous example.

You can also ask for a selectable value:

enum LicenseType {
    MIT,
    GPL,
    BSD,
}

let license = ineed::selected("The license type", [
    ("MIT", LicenseType::MIT),
    ("GPL", LicenseType::GPL),
    ("BSD", LicenseType::BSD),
])
    .prompt()
    .unwrap();

Or compose the prompts into one binding:

#[derive(Debug)]
enum Age {
    Minor,
    LegalAge,
    Unknown,
}

let (name, age) = ineed::written::<String>("Your name")
    .then(
        ineed::written::<u8>("How old are you?")
            .max_tries(3)
            .map(|age| match age {
                Ok(..18) => Age::Minor,
                Ok(_) => Age::LegalAge,
                Err(_exceeded) => Age::Unknown,
            })
    )
    .prompt()
    .unwrap();

println!("Your name is {name} and your age status is {age:?}");

There are many other promptable types, which are listed in the crate documentation.

You can also prompt for password. For this, you must add the rpassword feature:

cargo add ineed -F rpassword

which will give you access to the ineed::password promptable.

You can find more examples in the [/examples] folder.

Commit count: 39

cargo fmt