use super::Set;
use crate::{VersionError, version::Operator};
use clap::{Parser, Subcommand};
#[derive(Parser, Debug, Clone, PartialEq)]
#[command(arg_required_else_help(true))]
pub struct GetSetRm {
#[command(subcommand)]
pub command: GetSetRmCommand,
}
impl TryFrom<GetSetRm> for Operator {
type Error = VersionError;
fn try_from(cmd: GetSetRm) -> Result<Self, Self::Error> {
cmd.command.try_into()
}
}
impl TryFrom<&GetSetRm> for Operator {
type Error = VersionError;
fn try_from(cmd: &GetSetRm) -> Result<Self, Self::Error> {
(&cmd.command).try_into()
}
}
#[derive(Subcommand, Debug, Clone, PartialEq)]
pub enum GetSetRmCommand {
Get,
Set(Set),
Rm,
Reset,
}
impl TryFrom<&GetSetRmCommand> for Operator {
type Error = VersionError;
fn try_from(cmd: &GetSetRmCommand) -> Result<Self, Self::Error> {
match cmd {
GetSetRmCommand::Get => Ok(Operator::Get),
GetSetRmCommand::Set(set) => Ok(Operator::Set(set.try_into()?)),
GetSetRmCommand::Rm => Ok(Operator::Rm),
GetSetRmCommand::Reset => Ok(Operator::Reset),
}
}
}
impl TryFrom<GetSetRmCommand> for Operator {
type Error = VersionError;
fn try_from(cmd: GetSetRmCommand) -> Result<Self, Self::Error> {
match cmd {
GetSetRmCommand::Get => Ok(Operator::Get),
GetSetRmCommand::Set(set) => Ok(Operator::Set(set.try_into()?)),
GetSetRmCommand::Rm => Ok(Operator::Rm),
GetSetRmCommand::Reset => Ok(Operator::Reset),
}
}
}