Skip to content

Commit

Permalink
Add --list to known subcommands.
Browse files Browse the repository at this point in the history
`cross --list` should list the subcommands present for cargo in the
image, rather on the host. This works because any option provided before
a subcommand has priority over the subcommand. For example, `cargo build
--help` prints the help menu for `cargo build`, but `cargo --help build`
ignores `build` and prints the help for `cargo`. Therefore, the options
`--help`, `--version`, and `--list` can be treated as
pseudo-subcommands.

Fixes #715.
  • Loading branch information
Alexhuszagh committed May 25, 2022
1 parent c4f5ae4 commit d7180ce
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- #719 - add `--list` to known subcommands.
- #714 - use host target directory when falling back to host cargo.
- #713 - convert relative target directories to absolute paths.
- #709 - Update Emscripten targets to `emcc` version 3.1.10
Expand Down
4 changes: 3 additions & 1 deletion src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum Subcommand {
Deb,
Clippy,
Metadata,
List,
}

impl Subcommand {
Expand All @@ -30,7 +31,7 @@ impl Subcommand {
}

pub fn needs_target_in_command(self) -> bool {
!matches!(self, Subcommand::Metadata)
!matches!(self, Subcommand::Metadata | Subcommand::List)
}
}

Expand All @@ -47,6 +48,7 @@ impl<'a> From<&'a str> for Subcommand {
"deb" => Subcommand::Deb,
"clippy" => Subcommand::Clippy,
"metadata" => Subcommand::Metadata,
"--list" => Subcommand::List,
_ => Subcommand::Other,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn parse(target_list: &TargetList) -> Result<Args> {
all.push("--target-dir=/target".into());
}
} else {
if !arg.starts_with('-') && sc.is_none() {
if (!arg.starts_with('-') || arg == "--list") && sc.is_none() {
sc = Some(Subcommand::from(arg.as_ref()));
}

Expand Down

0 comments on commit d7180ce

Please sign in to comment.