version_manager/cli/getset/
mod.rs1pub mod build;
2pub mod rm;
3pub mod set;
4pub mod ver;
5
6pub use build::GetSetBuild;
7pub use rm::GetSetRm;
8pub use set::Set;
9pub use ver::SetVer;
10
11use crate::{VersionError, version::Operator};
12use clap::{Parser, Subcommand};
13
14#[derive(Parser, Debug, Clone, PartialEq)]
15#[command(arg_required_else_help(true))]
17pub struct GetSet {
18 #[command(subcommand)]
19 pub command: GetSetCommand,
20}
21
22impl TryFrom<GetSet> for Operator {
23 type Error = VersionError;
24
25 fn try_from(cmd: GetSet) -> Result<Self, Self::Error> {
26 cmd.command.try_into()
27 }
28}
29
30impl TryFrom<&GetSet> for Operator {
31 type Error = VersionError;
32
33 fn try_from(cmd: &GetSet) -> Result<Self, Self::Error> {
34 (&cmd.command).try_into()
35 }
36}
37
38#[derive(Subcommand, Debug, Clone, PartialEq)]
39pub enum GetSetCommand {
41 Get,
43 Set(Set),
45 Reset,
47}
48
49impl TryFrom<&GetSetCommand> for Operator {
50 type Error = VersionError;
51
52 fn try_from(cmd: &GetSetCommand) -> Result<Self, Self::Error> {
53 match cmd {
54 GetSetCommand::Get => Ok(Operator::Get),
55 GetSetCommand::Set(set) => Ok(Operator::Set(set.try_into()?)),
56 GetSetCommand::Reset => Ok(Operator::Reset),
57 }
58 }
59}
60
61impl TryFrom<GetSetCommand> for Operator {
62 type Error = VersionError;
63
64 fn try_from(cmd: GetSetCommand) -> Result<Self, Self::Error> {
65 match cmd {
66 GetSetCommand::Get => Ok(Operator::Get),
67 GetSetCommand::Set(set) => Ok(Operator::Set(set.try_into()?)),
68 GetSetCommand::Reset => Ok(Operator::Reset),
69 }
70 }
71}