version_manager/cli/
version.rs1use crate::{
2 VersionError,
3 cli::{
4 files::FilesCommand,
5 getset::{GetSet, GetSetBuild, GetSetRm, SetVer},
6 package::PackageCommand,
7 },
8 version::Scope,
9};
10use clap::Subcommand;
11
12#[derive(Subcommand, Debug, Clone, PartialEq)]
13#[command(rename_all = "lower", arg_required_else_help(true))]
15pub enum VersionCommand {
16 Major(GetSet),
18 Minor(GetSet),
20 Patch(GetSet),
22 Alpha(GetSetRm),
24 Beta(GetSetRm),
26 RC(GetSetRm),
28 Build(GetSetBuild),
30 Get,
32 Set(SetVer),
34 Version,
36 Revision,
38 File(FilesCommand),
40 Package(PackageCommand),
42}
43
44impl TryFrom<&VersionCommand> for Scope {
45 type Error = VersionError;
46
47 fn try_from(cmd: &VersionCommand) -> Result<Self, VersionError> {
48 let scope = match cmd {
49 VersionCommand::Major(getset) => Scope::Major(getset.try_into()?),
50 VersionCommand::Minor(getset) => Scope::Minor(getset.try_into()?),
51 VersionCommand::Patch(getset) => Scope::Patch(getset.try_into()?),
52 VersionCommand::Alpha(getset) => Scope::Alpha(getset.try_into()?),
53 VersionCommand::Beta(getset) => Scope::Beta(getset.try_into()?),
54 VersionCommand::RC(getset) => Scope::RC(getset.try_into()?),
55 VersionCommand::Build(getset) => Scope::Build(getset.try_into()?),
56 VersionCommand::Get => Scope::Get,
57 VersionCommand::Version => Scope::Version,
58 VersionCommand::Revision => Scope::Revision,
59 VersionCommand::File(file_cmd) => Scope::File(file_cmd.try_into()?),
60 VersionCommand::Package(package_cmd) => package_cmd.try_into()?,
61 VersionCommand::Set(setver) => Scope::Set(setver.try_into()?),
62 };
63 Ok(scope)
64 }
65}
66
67impl TryFrom<VersionCommand> for Scope {
68 type Error = VersionError;
69
70 fn try_from(cmd: VersionCommand) -> Result<Self, VersionError> {
71 let scope = match cmd {
72 VersionCommand::Major(getset) => Scope::Major(getset.try_into()?),
73 VersionCommand::Minor(getset) => Scope::Minor(getset.try_into()?),
74 VersionCommand::Patch(getset) => Scope::Patch(getset.try_into()?),
75 VersionCommand::Alpha(getset) => Scope::Alpha(getset.try_into()?),
76 VersionCommand::Beta(getset) => Scope::Beta(getset.try_into()?),
77 VersionCommand::RC(getset) => Scope::RC(getset.try_into()?),
78 VersionCommand::Build(getset) => Scope::Build(getset.try_into()?),
79 VersionCommand::Get => Scope::Get,
80 VersionCommand::Version => Scope::Version,
81 VersionCommand::Revision => Scope::Revision,
82 VersionCommand::File(file_cmd) => Scope::File(file_cmd.try_into()?),
83 VersionCommand::Package(package_cmd) => package_cmd.try_into()?,
84 VersionCommand::Set(setver) => Scope::Set(setver.try_into()?),
85 };
86 Ok(scope)
87 }
88}