-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove macro :(((((((((((((((((((((((((((((((((
- Loading branch information
Showing
6 changed files
with
23 additions
and
57 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,34 +1,10 @@ | ||
#[macro_export] | ||
macro_rules! generate_version_parser { | ||
($enum_name:ident, $variant1:ident, $variant2:ident ) => { | ||
use shared::print::print_as_warning; | ||
use anyhow::Error; | ||
use anyhow::Error; | ||
use clap::ValueEnum; | ||
use shared::print::print_as_warning; | ||
|
||
impl std::str::FromStr for $enum_name { | ||
type Err = String; | ||
const DEPRECATION_MESSAGE: &str = "The '--version' flag is deprecated and will be removed in the future. Version 3 will become the only type of transaction available."; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
let var1 = stringify!($variant1).to_lowercase(); | ||
let var2 = stringify!($variant2).to_lowercase(); | ||
|
||
match s.to_lowercase().as_str() { | ||
v if v == var1 => Ok($enum_name::$variant1), | ||
v if v == var2 => Ok($enum_name::$variant2), | ||
_ => Err(format!( | ||
"Invalid value '{}'. Possible values: {}, {}", | ||
s, var1, var2 | ||
)), | ||
} | ||
} | ||
} | ||
|
||
pub fn parse_version(s: &str) -> Result<$enum_name, String> { | ||
let deprecation_message = "The '--version' flag is deprecated and will be removed in the future. Version 3 will become the only type of transaction available."; | ||
print_as_warning(&Error::msg(deprecation_message)); | ||
|
||
let parsed_enum = s.parse::<$enum_name>()?; | ||
|
||
Ok(parsed_enum) | ||
} | ||
}; | ||
pub fn parse_version<T: ValueEnum>(s: &str) -> Result<T, String> { | ||
print_as_warning(&Error::msg(DEPRECATION_MESSAGE)); | ||
T::from_str(s, true) | ||
} |
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
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