version_manager/cli/getset/
set.rs1use crate::{VersionError, version::SetTypes};
2use clap::{Args, Subcommand, builder::RangedU64ValueParser};
3
4#[derive(Args, Debug, Clone, PartialEq)]
5pub struct Set {
7 #[arg(value_parser = RangedU64ValueParser::<u64>::new(), exclusive = true)]
8 pub value: Option<u64>,
10 #[command(subcommand)]
11 pub command: Option<UpDown>,
13}
14
15impl TryFrom<&Set> for SetTypes {
16 type Error = VersionError;
17
18 fn try_from(set: &Set) -> Result<Self, VersionError> {
19 if let Some(value) = &set.value {
20 return Ok(SetTypes::Number(*value));
21 } else if let Some(command) = &set.command {
22 return Ok(command.try_into()?);
23 } else {
24 Err(VersionError::NoValue)
25 }
26 }
27}
28
29impl TryFrom<Set> for SetTypes {
30 type Error = VersionError;
31
32 fn try_from(set: Set) -> Result<Self, VersionError> {
33 if let Some(value) = &set.value {
34 return Ok(SetTypes::Number(*value));
35 } else if let Some(command) = &set.command {
36 return Ok(command.try_into()?);
37 } else {
38 Err(VersionError::NoValue)
39 }
40 }
41}
42
43#[derive(Subcommand, Debug, Clone, PartialEq)]
44#[command(rename_all = "lower", arg_required_else_help(true))]
45pub enum UpDown {
46 #[command(name = "+")]
47 Plus,
49 #[command(name = "-")]
50 Minus,
52 Up,
54 Down,
56}
57
58impl TryFrom<&UpDown> for SetTypes {
59 type Error = VersionError;
60
61 fn try_from(updown: &UpDown) -> Result<Self, VersionError> {
62 match updown {
63 UpDown::Up => Ok(SetTypes::AddNumber),
64 UpDown::Down => Ok(SetTypes::SubNumber),
65 UpDown::Plus => Ok(SetTypes::AddNumber),
66 UpDown::Minus => Ok(SetTypes::SubNumber),
67 }
68 }
69}
70
71impl TryFrom<UpDown> for SetTypes {
72 type Error = VersionError;
73
74 fn try_from(updown: UpDown) -> Result<Self, VersionError> {
75 match updown {
76 UpDown::Up => Ok(SetTypes::AddNumber),
77 UpDown::Down => Ok(SetTypes::SubNumber),
78 UpDown::Plus => Ok(SetTypes::AddNumber),
79 UpDown::Minus => Ok(SetTypes::SubNumber),
80 }
81 }
82}