mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
refactor(xtask): prefer ? to Result::map in subcmd. parsing
This commit is contained in:
committed by
Teodor Tanasoaia
parent
cd7b8aca47
commit
3e11b4a3cd
129
xtask/src/cli.rs
129
xtask/src/cli.rs
@@ -54,24 +54,25 @@ pub(crate) enum Subcommand {
|
||||
|
||||
impl Subcommand {
|
||||
fn parse(mut args: Arguments) -> anyhow::Result<Subcommand> {
|
||||
args.subcommand()
|
||||
.context("failed to parse subcommand")
|
||||
.and_then(|parsed| match parsed.as_deref() {
|
||||
None => bail!("no subcommand specified; see `--help` for more details"),
|
||||
Some("all") => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::All)
|
||||
}
|
||||
Some("bench") => {
|
||||
let clean = args.contains("--clean");
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Bench { clean })
|
||||
}
|
||||
Some("validate") => Ok(Self::Validate(ValidateSubcommand::parse(args)?)),
|
||||
Some(other) => {
|
||||
bail!("unrecognized subcommand {other:?}; see `--help` for more details")
|
||||
}
|
||||
})
|
||||
let subcmd = args
|
||||
.subcommand()
|
||||
.context("failed to parse subcommand")?
|
||||
.context("no subcommand specified; see `--help` for more details")?;
|
||||
match &*subcmd {
|
||||
"all" => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::All)
|
||||
}
|
||||
"bench" => {
|
||||
let clean = args.contains("--clean");
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Bench { clean })
|
||||
}
|
||||
"validate" => Ok(Self::Validate(ValidateSubcommand::parse(args)?)),
|
||||
other => {
|
||||
bail!("unrecognized subcommand {other:?}; see `--help` for more details")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,35 +88,36 @@ pub(crate) enum ValidateSubcommand {
|
||||
|
||||
impl ValidateSubcommand {
|
||||
fn parse(mut args: Arguments) -> Result<Self, anyhow::Error> {
|
||||
args.subcommand()
|
||||
.context("failed to parse `validate` subcommand")
|
||||
.and_then(|parsed| match parsed.as_deref() {
|
||||
None => bail!("no `validate` subcommand specified; see `--help` for more details"),
|
||||
Some("spv") => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Spirv)
|
||||
}
|
||||
Some("msl") => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Metal)
|
||||
}
|
||||
Some("glsl") => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Glsl)
|
||||
}
|
||||
Some("dot") => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Dot)
|
||||
}
|
||||
Some("wgsl") => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Wgsl)
|
||||
}
|
||||
Some("hlsl") => Ok(Self::Hlsl(ValidateHlslCommand::parse(args)?)),
|
||||
Some(other) => bail!(
|
||||
"unrecognized `validate` subcommand {other:?}; see `--help` for more details"
|
||||
),
|
||||
})
|
||||
let subcmd = args
|
||||
.subcommand()
|
||||
.context("failed to parse `validate` subcommand")?
|
||||
.context("no `validate` subcommand specified; see `--help` for more details")?;
|
||||
match &*subcmd {
|
||||
"spv" => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Spirv)
|
||||
}
|
||||
"msl" => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Metal)
|
||||
}
|
||||
"glsl" => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Glsl)
|
||||
}
|
||||
"dot" => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Dot)
|
||||
}
|
||||
"wgsl" => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Wgsl)
|
||||
}
|
||||
"hlsl" => return Ok(Self::Hlsl(ValidateHlslCommand::parse(args)?)),
|
||||
other => {
|
||||
bail!("unrecognized `validate` subcommand {other:?}; see `--help` for more details")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,22 +129,23 @@ pub(crate) enum ValidateHlslCommand {
|
||||
|
||||
impl ValidateHlslCommand {
|
||||
fn parse(mut args: Arguments) -> anyhow::Result<Self> {
|
||||
args.subcommand()
|
||||
.context("failed to parse `hlsl` subcommand")
|
||||
.and_then(|parsed| match parsed.as_deref() {
|
||||
None => bail!("no `hlsl` subcommand specified; see `--help` for more details"),
|
||||
Some("dxc") => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Dxc)
|
||||
}
|
||||
Some("fxc") => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Fxc)
|
||||
}
|
||||
Some(other) => {
|
||||
bail!("unrecognized `hlsl` subcommand {other:?}; see `--help` for more details")
|
||||
}
|
||||
})
|
||||
let subcmd = args
|
||||
.subcommand()
|
||||
.context("failed to parse `hlsl` subcommand")?
|
||||
.context("no `hlsl` subcommand specified; see `--help` for more details")?;
|
||||
match &*subcmd {
|
||||
"dxc" => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Dxc)
|
||||
}
|
||||
"fxc" => {
|
||||
ensure_remaining_args_empty(args)?;
|
||||
Ok(Self::Fxc)
|
||||
}
|
||||
other => {
|
||||
bail!("unrecognized `hlsl` subcommand {other:?}; see `--help` for more details")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user