From 8156fcb53559afc5a784494d24398f6950fa15a1 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 31 Aug 2023 08:55:36 -0500 Subject: [PATCH] fix(cli): Help people find possible --target values --- src/cargo/util/command_prelude.rs | 12 +++++++++++- tests/testsuite/list_availables.rs | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 6ed1b8ed862f..aef8d0289afe 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -4,6 +4,7 @@ use crate::core::{Edition, Workspace}; use crate::ops::{CompileFilter, CompileOptions, NewOptions, Packages, VersionControl}; use crate::util::important_paths::find_root_manifest_for_wd; use crate::util::interning::InternedString; +use crate::util::is_rustup; use crate::util::restricted_names::is_glob_pattern; use crate::util::toml::{StringOrVec, TomlProfile}; use crate::util::validate_package_name; @@ -445,7 +446,16 @@ pub trait ArgMatchesExt { fn targets(&self) -> CargoResult> { if self.is_present_with_zero_values("target") { - bail!("\"--target\" takes an argument."); + let cmd = if is_rustup() { + "rustup target list" + } else { + "ustc --print target-list" + }; + bail!( + "\"--target\" takes an argument. + +Run `{cmd}` to see possible targets." + ); } Ok(self._values_of("target")) } diff --git a/tests/testsuite/list_availables.rs b/tests/testsuite/list_availables.rs index ec2f9bfabb3b..add90a7da8ac 100644 --- a/tests/testsuite/list_availables.rs +++ b/tests/testsuite/list_availables.rs @@ -167,6 +167,8 @@ No tests available. .with_stderr( "\ error: \"--target\" takes an argument. + +Run `[..]` to see possible targets. ", ) .with_status(101)