Skip to content

Commit

Permalink
Merge #833
Browse files Browse the repository at this point in the history
833: Fix error message with cross-util with invalid command. r=Emilgardis a=Alexhuszagh

Changes the error message to properly report the invalid command, when an invalid command is provided.

Co-authored-by: Alex Huszagh <[email protected]>
  • Loading branch information
bors[bot] and Alexhuszagh authored Jun 22, 2022
2 parents 05c4490 + ae5c1fb commit 5ef0830
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/bin/cross-util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![deny(missing_debug_implementations, rust_2018_idioms)]

use clap::{Parser, Subcommand};
use clap::{CommandFactory, Parser, Subcommand};

mod commands;

Expand All @@ -14,6 +14,13 @@ struct Cli {
command: Commands,
}

// hidden implied parser so we can get matches without recursion.
#[derive(Parser, Debug)]
struct CliHidden {
#[clap(subcommand)]
command: Commands,
}

#[derive(Subcommand, Debug)]
enum Commands {
/// List cross images in local storage.
Expand All @@ -25,7 +32,8 @@ fn is_toolchain(toolchain: &str) -> cross::Result<String> {
if toolchain.starts_with('+') {
Ok(toolchain.chars().skip(1).collect())
} else {
eyre::bail!("not a toolchain")
let _ = <CliHidden as CommandFactory>::command().get_matches();
unreachable!();
}
}

Expand Down
12 changes: 10 additions & 2 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod util;
use std::path::PathBuf;

use ci::CiJob;
use clap::{Parser, Subcommand};
use clap::{CommandFactory, Parser, Subcommand};
use util::ImageTarget;

use self::build_docker_image::BuildDockerImage;
Expand All @@ -28,6 +28,13 @@ struct Cli {
command: Commands,
}

// hidden implied parser so we can get matches without recursion.
#[derive(Parser, Debug)]
struct CliHidden {
#[clap(subcommand)]
command: Commands,
}

#[derive(Subcommand, Debug)]
enum Commands {
/// Extract and print info for targets.
Expand All @@ -49,7 +56,8 @@ fn is_toolchain(toolchain: &str) -> cross::Result<String> {
if toolchain.starts_with('+') {
Ok(toolchain.chars().skip(1).collect())
} else {
eyre::bail!("not a toolchain")
let _ = <CliHidden as CommandFactory>::command().get_matches();
unreachable!();
}
}

Expand Down

0 comments on commit 5ef0830

Please sign in to comment.