Skip to content

Commit f11ebdd

Browse files
committed
feat(cli): Accept 'cargo Cargo.toml'
This wasn't in the original Pre-RFC but in terms of consistently accepting manifests everything, I think this makes sense.
1 parent 476a1f7 commit f11ebdd

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/bin/cargo/cli.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ pub fn cli() -> Command {
492492
let usage = if is_rustup {
493493
"cargo [+toolchain] [OPTIONS] [COMMAND]\n cargo [+toolchain] [OPTIONS] -Zscript <MANIFEST_RS> [ARGS]..."
494494
} else {
495-
"cargo [OPTIONS] [COMMAND]\n cargo [OPTIONS] -Zscript <MANIFEST_RS> [ARGS]..."
495+
"cargo [OPTIONS] [COMMAND]\n cargo [OPTIONS] -Zscript <MANIFEST> [ARGS]..."
496496
};
497497
Command::new("cargo")
498498
// Subcommands all count their args' display order independently (from 0),

src/bin/cargo/commands/run.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
8787

8888
pub fn is_manifest_command(arg: &str) -> bool {
8989
let path = Path::new(arg);
90-
1 < path.components().count() || path.extension() == Some(OsStr::new("rs"))
90+
1 < path.components().count()
91+
|| path.extension() == Some(OsStr::new("rs"))
92+
|| path.file_name() == Some(OsStr::new("Cargo.toml"))
9193
}
9294

9395
pub fn exec_manifest_command(config: &Config, cmd: &str, args: &[OsString]) -> CliResult {

src/doc/src/reference/unstable.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1462,16 +1462,19 @@ persistent lockfile.
14621462

14631463
#### Manifest-commands
14641464

1465-
You may pass single-file packages directly to the `cargo` command, without subcommand. This is mostly intended for being put in `#!` lines.
1465+
You may pass a manifest directly to the `cargo` command, without a subcommand,
1466+
like `foo/Cargo.toml` or a single-file package like `foo.rs`. This is mostly
1467+
intended for being put in `#!` lines.
14661468

14671469
The precedence for how to interpret `cargo <subcommand>` is
14681470
1. Built-in xor single-file packages
14691471
2. Aliases
14701472
3. External subcommands
14711473

1472-
A parameter is identified as a single-file package if it has one of:
1474+
A parameter is identified as a manifest-command if it has one of:
14731475
- Path separators
14741476
- A `.rs` extension
1477+
- The file name is `Cargo.toml`
14751478

14761479
### `[lints]`
14771480

tests/testsuite/script.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,16 @@ fn basic_cargo_toml() {
7373

7474
p.cargo("-Zscript Cargo.toml")
7575
.masquerade_as_nightly_cargo(&["script"])
76-
.with_status(101)
77-
.with_stdout("")
76+
.with_stdout(
77+
r#"bin: target/debug/foo[EXE]
78+
args: []
79+
"#,
80+
)
7881
.with_stderr(
7982
"\
80-
error: no such command: `Cargo.toml`
81-
82-
<tab>View all installed commands with `cargo --list`
83+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
84+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
85+
[RUNNING] `target/debug/foo[EXE]`
8386
",
8487
)
8588
.run();

0 commit comments

Comments
 (0)