askr
askr (pronounced "asker") is a powerful, interactive CLI input tool for Rust that provides real-time validation, interactive choice menus, and a comprehensive validation system. Perfect for building robust command-line interfaces that need user input with validation.
✨ Features
- 🎯 Interactive Choice Menus - Navigate with arrow keys, select with Enter/Spacebar
- ⚡ Real-time Validation - Instant feedback as you type
- 🔍 Advanced Validation System - Email, URLs, numbers, dates, files, and custom patterns
- 🎨 Beautiful UI - Colored output, highlighted selections, and clear error messages
- 📊 Multiple Output Formats - Default, JSON, and raw output modes
- 🐚 Shell Completion - Support for bash, zsh, fish, and PowerShell
- 🔧 Highly Configurable - Validation priorities, custom messages, and flexible options
- 📚 Library + CLI - Use as a standalone tool or integrate into your Rust projects
📦 Installation
Install from crates.io
Install from source
🚀 Quick Start
Basic Usage
# Simple text input
# Required input with validation
# Email validation
# Number with range
Interactive Choice Menus
Single Choice:
Multiple Choices:

📖 Detailed Usage
Validation Options
Basic Validation
--required- Input cannot be empty--min-length <N>- Minimum character length--max-length <N>- Maximum character length--pattern <REGEX>- Custom regex pattern
Built-in Validators
--validate-email- Email address validation--validate-hostname- Hostname/domain validation--validate-url- URL validation--validate-ipv4- IPv4 address validation--validate-ipv6- IPv6 address validation
Number Validation
--integer- Accept only integers--float- Accept only floating-point numbers--range <MIN>-<MAX>- Numeric range (e.g.,--range 1-100)--positive- Only positive numbers--negative- Only negative numbers
Date/Time Validation
--date- Date input (default format: YYYY-MM-DD)--time- Time input (default format: HH:MM:SS)--datetime- DateTime input--date-format <FORMAT>- Custom date format--time-format <FORMAT>- Custom time format
Choice Validation
--choices <LIST>- Comma-separated list of valid choices--min-choices <N>- Minimum selections required (default: 1)--max-choices <N>- Maximum selections allowed (default: 1)--choices-case-sensitive- Case-sensitive choice matching
File System Validation
--file-exists- File must exist--dir-exists- Directory must exist--path-exists- File or directory must exist--readable- Path must be readable--writable- Path must be writable--executable- File must be executable
Output Options
Output Formats
--output default- Standard output with exit codes--output json- JSON object with validation metadata--output raw- Raw user input without processing
Display Control
--no-color- Disable colored output--quiet- Non-interactive mode, read from stdin--verbose- Show detailed validation messages
Interaction Control
--timeout <SECONDS>- Input timeout--max-attempts <N>- Maximum validation attempts--default <VALUE>- Default value if user presses Enter--mask- Mask input (for passwords)
💻 Examples
Complex Validation
# Strong password requirements
# Multi-constraint username
Choice Selection
# Single choice with arrow key navigation
env=
# Multiple features selection
features=
# Optional selection (0 or 1 choice)
optional=
JSON Output for Scripting
# Get structured output
result=
email=
valid=
if [; then
fi
Non-interactive Usage
# Validate from stdin
|
# Batch processing
| while ; do
if | ; then
else
fi
done
🐚 Shell Completion
Enable shell completion for better CLI experience:
Bash
Zsh
# Add to .zshrc: fpath=(~/.zsh/completions $fpath)
Fish
PowerShell
askr completion powershell | Out-String | Invoke-Expression
🛠️ Library Usage
Use askr as a library in your Rust projects:
[]
= "0.1"
use ;
📊 Exit Codes
0- Success (valid input received)1- Validation failed or invalid input2- Invalid command-line arguments3- Maximum attempts exceeded130- User interrupted (Ctrl+C)124- Timeout exceeded
🤝 Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Development
Pre-commit Hooks
This project uses pre-commit hooks to ensure code quality. To set up pre-commit hooks:
# Install pre-commit (if you don't have it)
# Install the git hook scripts
# (Optional) run against all files
The pre-commit configuration includes:
- Rust formatting with
cargo fmt - Focused linting with
cargo clippy(unused imports, style issues) - Compilation checks with
cargo check - Test execution with
cargo test - Basic file checks (trailing whitespace, file endings, etc.)
📄 License
This project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
🙏 Acknowledgments
- Inspired by Inquirer.js for interactive prompts
- Built with crossterm for cross-platform terminal control
- Uses clap for CLI argument parsing