-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): use
fix --replace
to auto fix icons
- Loading branch information
Showing
4 changed files
with
124 additions
and
71 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
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,44 @@ | ||
use crate::error; | ||
use inquire::InquireError; | ||
use std::{fmt, str::FromStr}; | ||
use thisctx::{IntoError, WithContext}; | ||
|
||
pub fn prompt_yes_or_no(msg: &str, help: Option<&str>) -> error::Result<YesOrNo> { | ||
match inquire::CustomType::<YesOrNo>::new(msg) | ||
.with_help_message(help.unwrap_or("Yes/No/All yes, <Ctrl-C> to abort")) | ||
.prompt() | ||
{ | ||
Err(InquireError::OperationInterrupted) => error::Interrupted.fail(), | ||
t => t.context(error::Prompt), | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub enum YesOrNo { | ||
Yes, | ||
No, | ||
AllYes, | ||
} | ||
|
||
impl fmt::Display for YesOrNo { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
YesOrNo::Yes => write!(f, "yes"), | ||
YesOrNo::No => write!(f, "no"), | ||
YesOrNo::AllYes => write!(f, "all yes"), | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for YesOrNo { | ||
type Err = &'static str; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s.to_lowercase().as_str() { | ||
"y" | "yes" => Ok(Self::Yes), | ||
"n" | "no" => Ok(Self::No), | ||
"a" | "all" => Ok(Self::AllYes), | ||
_ => Err("invalid input"), | ||
} | ||
} | ||
} |
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