Skip to content

Commit

Permalink
#4 fixing a parsing bug by removing newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
hlafaille committed Mar 19, 2024
1 parent a973172 commit 2618a9f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/frontend/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub async fn add(
print_general(format!("Searching for '{}'", q).as_str());
let packages = backend::dependency::resolve::query(q).await?;
for (elem, package) in packages.iter().enumerate() {
print_general(format!("{}) G:{} | A:{}", elem + 1, package.group_id, package.artifact_id).as_str());
print_general(format!("{}) {}:{}", elem + 1, package.group_id, package.artifact_id).as_str());
}

// collect the package selection if there was more than one returned package
Expand All @@ -130,11 +130,14 @@ pub async fn add(
print_err("Failed to read user package selection")
}

// remove any newlines
package_number_selection = package_number_selection.replace("\n", "");

// convert the input into a u64
let package_number_selection_int: u64 = match package_number_selection.parse::<u64>() {
Ok(v) => v,
Err(e) => {
print_err("Failed to parse user input as an unsigned integer.");
print_err(format!("Failed to parse user input as an unsigned integer: Input was '{}'", package_number_selection).as_str());
panic!("{}", e);
}
};
Expand All @@ -152,7 +155,6 @@ pub async fn add(
panic!()
}

println!("You selected: {}", selected_package.artifact_id);
// pass ownership back
Ok((p_ctx, tc_ctx))
}

0 comments on commit 2618a9f

Please sign in to comment.