-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use super::theme::ColoredTheme; | ||
use dialoguer; | ||
use std::io::Result; | ||
use structopt::StructOpt; | ||
|
||
#[derive(Debug, StructOpt)] | ||
/// Prompt that takes user input and returns a string. | ||
pub struct Input { | ||
#[structopt(short, long)] | ||
/// Message for the prompt | ||
message: String, | ||
|
||
#[structopt(short, long)] | ||
/// Default value for the prompt | ||
default: Option<String>, | ||
|
||
/// Allow empty input. Conflicts with `default` | ||
#[structopt(short, long, conflicts_with = "default")] | ||
allow_empty: bool, | ||
} | ||
|
||
impl Input { | ||
pub fn run(&self) -> Result<()> { | ||
let theme = ColoredTheme::default(); | ||
let mut input = dialoguer::Input::<String>::with_theme(&theme); | ||
|
||
input | ||
.with_prompt(&self.message) | ||
.allow_empty(self.allow_empty); | ||
|
||
if self.default.is_some() { | ||
input.default(self.default.as_ref().unwrap().to_string()); | ||
} | ||
|
||
let value = input.interact()?; | ||
|
||
println!("{}", value); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters