askit 0.1.0

A simple and semantic library to ask for user input in CLI applications. Type-safe parsing, defaults and retries.
Documentation
  • Coverage
  • 58.82%
    10 out of 17 items documented1 out of 1 items with examples
  • Size
  • Source code size: 25.97 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.29 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Bruno-Gomes-QA/askit
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Bruno-Gomes-QA

askit

askit is a simple and semantic Rust library to handle interactive CLI prompts, inspired by Python's input.
It provides an ergonomic and type-safe way to ask users for values, validate them, and display custom messages.


Features

  • input! macro: Ask the user for input with minimal boilerplate.
  • Typed input: Directly parse inputs into Rust types like i32, f64, bool, String, and more.
  • Validation: Attach custom validation logic.
  • Messages: Attach messages or hints to guide the user.
  • Defaults: Provide default values if the user presses Enter.

Installation

Add the following to your Cargo.toml:

[dependencies]
askit = "0.1.0"

Quickstart

use askit::input;

fn main() {
    // Basic input as string
    let name: String = input!("What is your name? ");
    println!("Hello, {}!", name);

    // Input as integer
    let age: i32 = input!("How old are you? ");
    println!("You are {} years old.", age);

    // With default value
    let country: String = askit::Input::new("Your country: ")
        .default("Brazil".to_string())
        .get();
    println!("Country: {}", country);

    // With validation
    let age: i32 = askit::Input::new("Age (must be > 18): ")
        .validate(|&n| if n > 18 { Ok(()) } else { Err("Age must be > 18".into()) })
        .get();
    println!("Validated Age: {}", age);
}

Usage Examples

1. Basic input! macro

use askit::input;

fn main() {
    let name: String = input!("Enter your name: ");
    let age: i32 = input!("Enter your age: ");
    println!("{} is {} years old.", name, age);
}

2. With default values

use askit::Input;

fn main() {
    let language: String = Input::new("Favorite language: ")
        .default("Rust".to_string())
        .get();
    println!("Favorite language: {}", language);
}

3. With validation

use askit::Input;

fn main() {
    let score: i32 = Input::new("Score (0-100): ")
        .validate(|&s| {
            if (0..=100).contains(&s) {
                Ok(())
            } else {
                Err("Score must be between 0 and 100".into())
            }
        })
        .get();
    println!("Validated score: {}", score);
}

Running Examples

Run the examples included in the repository:

cargo run --example basic
cargo run --example validation

Testing

Run the test suite:

cargo test

Development Guide

Branching Strategy

  • main: Always production-ready.
  • develop: Integration branch for new features.
  • feature/*: Each feature should have its own branch.
  • hotfix/*: For urgent fixes to production.

Commit Convention

Follow the Conventional Commits standard:

  • feat: – New feature.
  • fix: – Bug fix.
  • docs: – Documentation changes.
  • style: – Code style changes (formatting, etc).
  • refactor: – Code refactoring.
  • test: – Adding or fixing tests.
  • chore: – Other changes (build tools, CI, etc).

Example:

feat(input): add default typed values
fix(validate): correct error message display

License

MIT License.