Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update deps and add PortId ArgParser implementation
Browse files Browse the repository at this point in the history
seanchen1991 committed Jan 17, 2025
1 parent ffe0552 commit edd565b
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/cli/cli-components/Cargo.toml
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ hermes-test-components = { workspace = true }

cgp = { workspace = true }
http = { workspace = true }
ibc = { workspace = true }
serde = { workspace = true, features = ["derive"] }
toml = { workspace = true }
clap = { workspace = true, features = ["derive"] }
33 changes: 33 additions & 0 deletions crates/cli/cli-components/src/impls/parse/identifier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use core::marker::PhantomData;
use core::str::FromStr;

use cgp::prelude::*;
use ibc::core::host::types::identifiers::PortId;

use crate::traits::parse::ArgParser;

const TRANSFER_PORT_ID: &str = "transfer";

pub struct ParsePortId<Parsed>(pub PhantomData<Parsed>);

impl<App, Args, Tag, Parsed> ArgParser<App, Args, Tag> for ParsePortId<Parsed>
where
App: CanRaiseAsyncError<Parsed::Err>,
Args: HasField<Tag, Value = String>,
Parsed: Async + FromStr,
{
type Parsed = PortId;

fn parse_arg(_app: &App, args: &Args, _tag: PhantomData<Tag>) -> Result<Parsed, App::Error> {
let port_id: PortId = args
.get_field(PhantomData)
.parse()
.map_err(App::raise_error)?;

if port_id.validate().is_err() {
Ok(PortId::new(TRANSFER_PORT_ID.to_string()))
} else {
Ok(port_id)
}
}
}
1 change: 1 addition & 0 deletions crates/cli/cli-components/src/impls/parse/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod field;
pub mod identifier;
pub mod string;

0 comments on commit edd565b

Please sign in to comment.