A Command Line Question Asker for Rust.
Easy to use library for asking users questions when writing console/terminal applications.
This package is passively maintained. Don't let the inactivity fool you issues and feature requests will be addressed. It is due to being a small focused library that just works so well nothing has had to be done.
Add question
as a dependency in your Cargo.toml
to use from crates.io:
[dependencies]
question = "0.2.2"
Then add extern crate question;
to your crate root and run cargo build
or cargo update && cargo build
for your project. Detailed documentation for releases can be found on docs.rs.
extern crate question;
use question::{Answer, Question};
fn main() {
let answer = Question::new("Continue?")
.default(Answer::YES)
.show_defaults()
.confirm();
if answer == Answer::YES {
println!("Onward then!");
} else {
println!("Aborting...");
}
}
Examples can also be ran directly:
$ cargo run --example yes_no_with_defaults
Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
Running `target/debug/examples/yes_no_with_defaults`
Continue? (Y/n) why
Continue? (Y/n) y
Onward then!
See examples for more.
To contribute to Question, please see CONTRIBUTING.
Question is distributed under the terms of the MIT license. If this does not suit your needs for some reason please feel free to contact me, or open a discussion.
See LICENSE.