Skip to content

Commit eb63b88

Browse files
authored
fix(ic_admin): adjust proposal URL handling (#1378)
1 parent 4a86d75 commit eb63b88

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

rs/cli/src/ic_admin.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,31 @@ impl IcAdmin for IcAdminImpl {
151151
fn simulate_proposal(&self, cmd: Vec<String>, forum_post_link_description: Option<String>) -> BoxFuture<'_, anyhow::Result<()>> {
152152
Box::pin(async move {
153153
debug!("Simulating proposal {:?}.", cmd);
154-
let mut args = Self::add_proposal_url(self.add_proposer(cmd), forum_post_link_description);
154+
155+
// If the forum post link description is a valid URL, and add it to the arguments if it is.
156+
// Otherwise, add the forum post link description as a string after the ic-admin command.
157+
let is_forum_post_link_description_url = forum_post_link_description
158+
.as_ref()
159+
.map(|desc| url::Url::parse(desc).is_ok())
160+
.unwrap_or(false);
161+
let mut args = if is_forum_post_link_description_url {
162+
Self::add_proposal_url(self.add_proposer(cmd), forum_post_link_description.clone())
163+
} else {
164+
self.add_proposer(cmd)
165+
};
166+
155167
// Make sure there is no more than one `--dry-run` argument, or else ic-admin will complain.
156168
if !args.contains(&String::from("--dry-run")) {
157169
args.push("--dry-run".into())
158170
};
159171

160172
self.run(args.as_slice(), true).await.map(|r| r.trim().to_string())?;
173+
174+
// Add the forum post link description as a string after the ic-admin command.
175+
if forum_post_link_description.is_some() && !is_forum_post_link_description_url {
176+
println!("Forum post link: {}", forum_post_link_description.unwrap());
177+
}
178+
161179
Ok(())
162180
})
163181
}

0 commit comments

Comments
 (0)