-
Notifications
You must be signed in to change notification settings - Fork 65
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
FroVolod
committed
Feb 8, 2025
1 parent
0c1d2f8
commit a165d9d
Showing
4 changed files
with
93 additions
and
26 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
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 @@ | ||
#[derive(Debug, Default, Clone)] | ||
pub struct OptionalString(Option<String>); | ||
|
||
impl std::fmt::Display for OptionalString { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
if let Some(s) = &self.0 { | ||
s.fmt(f) | ||
} else { | ||
write!(f, "") | ||
} | ||
} | ||
} | ||
|
||
impl std::str::FromStr for OptionalString { | ||
type Err = color_eyre::eyre::ErrReport; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
let trimmed = s.trim(); | ||
if trimmed.is_empty() { | ||
Ok(Self(None)) | ||
} else { | ||
Ok(Self(Some(trimmed.to_lowercase()))) | ||
} | ||
} | ||
} | ||
|
||
impl From<OptionalString> for Option<String> { | ||
fn from(item: OptionalString) -> Self { | ||
item.0 | ||
} | ||
} | ||
|
||
impl From<Option<String>> for OptionalString { | ||
fn from(item: Option<String>) -> Self { | ||
Self(item) | ||
} | ||
} | ||
|
||
impl interactive_clap::ToCli for OptionalString { | ||
type CliVariant = OptionalString; | ||
} |