Skip to content

Commit 3fbd5ae

Browse files
committed
Add --index flag to cargo install
1 parent fb0e392 commit 3fbd5ae

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn cli() -> App {
1818
.arg(
1919
opt("git", "Git URL to install the specified crate from")
2020
.value_name("URL")
21-
.conflicts_with_all(&["path", "registry"]),
21+
.conflicts_with_all(&["path", "index", "registry"]),
2222
)
2323
.arg(
2424
opt("branch", "Branch to use when installing from git")
@@ -38,7 +38,7 @@ pub fn cli() -> App {
3838
.arg(
3939
opt("path", "Filesystem path to local crate to install")
4040
.value_name("PATH")
41-
.conflicts_with_all(&["git", "registry"]),
41+
.conflicts_with_all(&["git", "index", "registry"]),
4242
)
4343
.arg(opt(
4444
"list",
@@ -58,11 +58,17 @@ pub fn cli() -> App {
5858
)
5959
.arg_target_triple("Build for the target triple")
6060
.arg(opt("root", "Directory to install packages into").value_name("DIR"))
61+
.arg(
62+
opt("index", "Registry index to install from")
63+
.value_name("INDEX")
64+
.requires("crate")
65+
.conflicts_with_all(&["git", "path", "registry"]),
66+
)
6167
.arg(
6268
opt("registry", "Registry to use")
6369
.value_name("REGISTRY")
6470
.requires("crate")
65-
.conflicts_with_all(&["git", "path"]),
71+
.conflicts_with_all(&["git", "path", "index"]),
6672
)
6773
.after_help(
6874
"\
@@ -100,8 +106,6 @@ continuous integration systems.",
100106
}
101107

102108
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
103-
let registry = args.registry(config)?;
104-
105109
if let Some(path) = args.value_of_path("path", config) {
106110
config.reload_rooted_at(path)?;
107111
} else {
@@ -143,8 +147,10 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
143147
} else if krates.is_empty() {
144148
from_cwd = true;
145149
SourceId::for_path(config.cwd())?
146-
} else if let Some(registry) = registry {
150+
} else if let Some(registry) = args.registry(config)? {
147151
SourceId::alt_registry(config, &registry)?
152+
} else if let Some(index) = args.value_of("index") {
153+
SourceId::for_registry(&index.into_url()?)?
148154
} else {
149155
SourceId::crates_io(config)?
150156
};

0 commit comments

Comments
 (0)