cli-prompt-helper

Crates.iocli-prompt-helper
lib.rscli-prompt-helper
version0.1.0
created_at2025-11-30 21:02:59.112544+00
updated_at2025-11-30 21:02:59.112544+00
descriptionsmall light weight crate for helper functions to prompt on stdin/stdout for small CLIs.
homepagehttps://github.com/thegreatbey/cli-prompt-helper
repositoryhttps://github.com/thegreatbey/cli-prompt-helper
max_upload_size
id1958849
size26,443
(thegreatbey)

documentation

https://github.com/thegreatbey/cli-prompt-helper/README.md

README

cli-prompt-helper

Dependency-free helpers to ask questions on stdin/stdout for small CLIs.

What you get:

  • prompt_str: print a prompt and read a single line (no trailing newline)
  • prompt_default: show a default and return it on empty input
  • prompt_parse: parse once using FromStr (e.g. u32)
  • prompt_yes_no: accept y/yes or n/no (case-insensitive), with a default

All functions block on stdin and use UTF-8. No unsafe code.

Examples

use cli_prompt_helper::{prompt_str, prompt_parse, prompt_default, prompt_yes_no};

fn main() -> Result<(), Box<dyn std::error::Error>> {
	let name = prompt_str("name: ")?;
	let age: u32 = prompt_parse("age: ")?;
	let city = prompt_default("city", "London")?;
	let proceed = prompt_yes_no("continue?", true)?;

	println!("{name} ({age}) from {city}; proceed={proceed}");
	Ok(())
}

Or run the included example:

cargo run --example basic

Why

//reduce boilerplate for tiny CLIs //avoid external dependencies for basic stdin/stdout prompts

Safety

//no unsafe code //simple, explicit control flow

License

Licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 0

cargo fmt