Change typeof Args::targets to Option<Vec<String>> (#327)

* Change typeof `Args::targets` to `Option<Vec<String>>`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-08-31 14:48:15 +10:00 committed by GitHub
parent 480ea19462
commit b330a18d40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 5 deletions

View file

@ -60,7 +60,7 @@ pub struct Args {
long, long,
value_name = "TRIPLE" value_name = "TRIPLE"
)] )]
pub targets: Option<String>, pub targets: Option<Vec<String>>,
/// Override Cargo.toml package manifest path. /// Override Cargo.toml package manifest path.
/// ///

View file

@ -29,7 +29,7 @@ pub async fn install_crates(mut args: Args, jobserver_client: LazyJobserverClien
}; };
// Launch target detection // Launch target detection
let desired_targets = get_desired_targets(args.targets.as_deref()); let desired_targets = get_desired_targets(args.targets.take());
// Initialize reqwest client // Initialize reqwest client
let client = create_reqwest_client(args.secure, args.min_tls_version.map(|v| v.into()))?; let client = create_reqwest_client(args.secure, args.min_tls_version.map(|v| v.into()))?;

View file

@ -50,9 +50,9 @@ impl DesiredTargets {
/// Since `detect_targets` internally spawns a process and wait for it, /// Since `detect_targets` internally spawns a process and wait for it,
/// it's pretty costy, it is recommended to run this fn ASAP and /// it's pretty costy, it is recommended to run this fn ASAP and
/// reuse the result. /// reuse the result.
pub fn get_desired_targets(opts_targets: Option<&str>) -> DesiredTargets { pub fn get_desired_targets(opts_targets: Option<Vec<String>>) -> DesiredTargets {
if let Some(targets) = opts_targets { if let Some(targets) = opts_targets {
DesiredTargets::initialized(targets.split(',').map(|t| t.to_string()).collect()) DesiredTargets::initialized(targets)
} else { } else {
DesiredTargets::auto_detect() DesiredTargets::auto_detect()
} }

View file

@ -35,7 +35,10 @@
//! # async fn main() { //! # async fn main() {
//! //!
//! assert_eq!( //! assert_eq!(
//! get_desired_targets(Some("x86_64-apple-darwin,aarch64-apple-darwin")).get().await, //! get_desired_targets(Some(vec![
//! "x86_64-apple-darwin".to_string(),
//! "aarch64-apple-darwin".to_string(),
//! ])).get().await,
//! &["x86_64-apple-darwin", "aarch64-apple-darwin"], //! &["x86_64-apple-darwin", "aarch64-apple-darwin"],
//! ); //! );
//! # } //! # }