-
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
6 changed files
with
139 additions
and
19 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 |
---|---|---|
@@ -1,7 +1,16 @@ | ||
# Changelog | ||
|
||
## master | ||
|
||
### Enhancements | ||
* Added `secret` subcommand | ||
|
||
### Breaking | ||
* Changed structure of the theme | ||
|
||
## 0.1.0 | ||
|
||
### Enhancements | ||
* Added `confirm` subcommand | ||
* Added `input` subcommand | ||
* Added a theme for `dialoguer` library |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use super::theme::ColoredTheme; | ||
use dialoguer::PasswordInput; | ||
use std::io::Result; | ||
use structopt::StructOpt; | ||
|
||
#[derive(Debug, StructOpt)] | ||
/// Prompt that takes user input, hides it from the terminal, and returns a string | ||
pub struct Secret { | ||
#[structopt(short, long)] | ||
/// Message for the prompt | ||
message: String, | ||
|
||
/// Enable confirmation prompt with this message | ||
#[structopt(short, long, requires = "error")] | ||
confirm: Option<String>, | ||
|
||
/// Error message when secrets doesn't match during confirmation | ||
#[structopt(short, long, requires = "confirm")] | ||
error: Option<String>, | ||
|
||
/// Allow empty secret | ||
#[structopt(short, long)] | ||
allow_empty: bool, | ||
} | ||
|
||
impl Secret { | ||
pub fn run(&self) -> Result<()> { | ||
let theme = ColoredTheme::default(); | ||
let mut input = PasswordInput::with_theme(&theme); | ||
|
||
input | ||
.with_prompt(&self.message) | ||
.allow_empty_password(self.allow_empty); | ||
|
||
if self.confirm.is_some() { | ||
input.with_confirmation( | ||
self.confirm.as_ref().unwrap(), | ||
&self.error.as_ref().unwrap(), | ||
); | ||
} | ||
|
||
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