-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add alias support to
contract asset deploy
(#1829)
- Loading branch information
Showing
5 changed files
with
81 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use crate::commands::global; | ||
|
||
pub mod asset; | ||
pub mod utils; | ||
pub mod wasm; | ||
|
||
#[derive(Debug, clap::Subcommand)] | ||
|
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,56 @@ | ||
use regex::Regex; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error( | ||
"alias must be 1-30 chars long, and have only letters, numbers, underscores and dashes" | ||
)] | ||
InvalidAliasFormat { alias: String }, | ||
} | ||
|
||
pub fn alias_validator(alias: &str) -> Result<String, Error> { | ||
let regex = Regex::new(r"^[a-zA-Z0-9_-]{1,30}$").unwrap(); | ||
|
||
if regex.is_match(alias) { | ||
Ok(alias.into()) | ||
} else { | ||
Err(Error::InvalidAliasFormat { | ||
alias: alias.into(), | ||
}) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_alias_validator_with_valid_inputs() { | ||
let valid_inputs = [ | ||
"hello", | ||
"123", | ||
"hello123", | ||
"hello_123", | ||
"123_hello", | ||
"123-hello", | ||
"hello-123", | ||
"HeLlo-123", | ||
]; | ||
|
||
for input in valid_inputs { | ||
let result = alias_validator(input); | ||
assert!(result.is_ok()); | ||
assert!(result.unwrap() == input); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_alias_validator_with_invalid_inputs() { | ||
let invalid_inputs = ["", "invalid!", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]; | ||
|
||
for input in invalid_inputs { | ||
let result = alias_validator(input); | ||
assert!(result.is_err()); | ||
} | ||
} | ||
} |
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