feat(adx): restore support for single character alias

This commit is contained in:
Harsh Shandilya 2022-12-08 12:27:05 +00:00
parent 439adc6880
commit 2589087822
1 changed files with 18 additions and 1 deletions

View File

@ -1,3 +1,4 @@
use clap::builder::PossibleValue;
use clap::ValueEnum;
use semver::{Prerelease, Version};
use std::cmp::{Eq, PartialEq, PartialOrd};
@ -10,7 +11,7 @@ use thiserror::Error;
/// Since we're deriving `PartialOrd` automatically, the order
/// of these fields is crucial. Sort by stability, not alphabetical
/// order.
#[derive(Debug, Eq, PartialEq, PartialOrd, Clone, Copy, ValueEnum)]
#[derive(Debug, Eq, PartialEq, PartialOrd, Clone, Copy)]
pub(crate) enum Channel {
Dev,
Alpha,
@ -19,6 +20,22 @@ pub(crate) enum Channel {
Stable,
}
impl ValueEnum for Channel {
fn value_variants<'a>() -> &'a [Self] {
&[Self::Dev, Self::Alpha, Self::Beta, Self::Rc, Self::Stable]
}
fn to_possible_value(&self) -> Option<PossibleValue> {
match self {
Channel::Dev => Some(PossibleValue::new("dev").alias("d")),
Channel::Alpha => Some(PossibleValue::new("alpha").alias("a")),
Channel::Beta => Some(PossibleValue::new("beta").alias("b")),
Channel::Stable => Some(PossibleValue::new("stable").alias("s")),
Channel::Rc => Some(PossibleValue::new("rc").alias("r")),
}
}
}
#[derive(Debug, Error)]
pub(crate) enum ChannelError {
#[error("no match found")]