Skip to content

Commit 7e2846f

Browse files
committed
Make resolve_post_client agnostic of FetchPostArgs
So it could be made more generic and reusable for any future subcommands that might need such conversion too
1 parent b694a30 commit 7e2846f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

wp_rs_cli/src/bin/wp_rs_cli/main.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,7 @@ fn parse_post_id(s: &str) -> Result<PostId, String> {
413413
.map_err(|e| format!("Invalid post id '{s}': {e}"))
414414
}
415415

416-
async fn resolve_post_id(client: &WpApiClient, args: &FetchPostArgs) -> Result<PostId> {
417-
if let Some(id) = args.post_id {
418-
return Ok(id);
419-
}
420-
let Some(post_url) = &args.url else {
421-
return Err(anyhow!("Either --post-id or --url must be provided"));
422-
};
423-
416+
async fn resolve_post_id(client: &WpApiClient, post_url: &str) -> Result<PostId> {
424417
// Strategy: retrieve by slug via posts list API when possible.
425418
// For wp.com, the resolver requires site context; for wp.org, api_root is given.
426419
// We'll try to parse the URL and extract a last path segment as potential slug.
@@ -456,7 +449,15 @@ async fn resolve_post_id(client: &WpApiClient, args: &FetchPostArgs) -> Result<P
456449
async fn fetch_post_and_comments(args: FetchPostArgs) -> Result<()> {
457450
let client = build_api_client(&args.auth, &args.url).await?;
458451

459-
let post_id = resolve_post_id(&client, &args).await?;
452+
let post_id = if let Some(id) = args.post_id {
453+
id
454+
} else {
455+
let post_url = args
456+
.url
457+
.as_ref()
458+
.ok_or_else(|| anyhow!("Either --post-id or --url must be provided"))?;
459+
resolve_post_id(&client, post_url.as_str()).await?
460+
};
460461

461462
let post = client
462463
.posts()

0 commit comments

Comments
 (0)