version_manager/cli/getset/
build.rs1use crate::{
2 VersionError,
3 version::{Operator, SetTypes},
4};
5use clap::{Args, Parser, Subcommand, builder::NonEmptyStringValueParser};
6
7#[derive(Parser, Debug, Clone, PartialEq)]
8#[command(arg_required_else_help(true))]
10pub struct GetSetBuild {
11 #[command(subcommand)]
12 pub command: GetSetBuildCommand,
13}
14
15impl TryFrom<GetSetBuild> for Operator {
16 type Error = VersionError;
17
18 fn try_from(cmd: GetSetBuild) -> Result<Self, Self::Error> {
19 cmd.command.try_into()
20 }
21}
22
23impl TryFrom<&GetSetBuild> for Operator {
24 type Error = VersionError;
25
26 fn try_from(cmd: &GetSetBuild) -> Result<Self, Self::Error> {
27 (&cmd.command).try_into()
28 }
29}
30
31#[derive(Subcommand, Debug, Clone, PartialEq)]
32pub enum GetSetBuildCommand {
34 Get,
35 Set(SetBuild),
36 Rm,
37}
38
39impl TryFrom<&GetSetBuildCommand> for Operator {
40 type Error = VersionError;
41
42 fn try_from(cmd: &GetSetBuildCommand) -> Result<Self, Self::Error> {
43 let op = match cmd {
44 GetSetBuildCommand::Get => Operator::Get,
45 GetSetBuildCommand::Set(set) => Operator::Set(set.try_into()?),
46 GetSetBuildCommand::Rm => Operator::Rm,
47 };
48 Ok(op)
49 }
50}
51
52impl TryFrom<GetSetBuildCommand> for Operator {
53 type Error = VersionError;
54
55 fn try_from(cmd: GetSetBuildCommand) -> Result<Self, Self::Error> {
56 let op = match cmd {
57 GetSetBuildCommand::Get => Operator::Get,
58 GetSetBuildCommand::Set(set) => Operator::Set(set.try_into()?),
59 GetSetBuildCommand::Rm => Operator::Rm,
60 };
61 Ok(op)
62 }
63}
64
65#[derive(Args, Debug, Clone, PartialEq)]
66pub struct SetBuild {
68 #[arg(value_parser = NonEmptyStringValueParser::new())]
69 pub value: String,
70}
71
72impl TryFrom<SetBuild> for SetTypes {
73 type Error = VersionError;
74
75 fn try_from(set: SetBuild) -> Result<Self, Self::Error> {
76 Ok(SetTypes::String(set.value))
77 }
78}
79
80impl TryFrom<&SetBuild> for SetTypes {
81 type Error = VersionError;
82
83 fn try_from(set: &SetBuild) -> Result<Self, Self::Error> {
84 Ok(SetTypes::String(set.value.clone()))
85 }
86}