use std::process::Command;
#[cfg(not(feature = "lt2022_1"))]
use super::IdentityChangeListMode;
#[cfg(not(feature = "lt2015_2"))]
use super::OnlyIdentityChangeListMode;
use super::{
Change, ExclusiveOption, ForceOperationMode, OnlyForceOperationMode,
OnlyOriginalChangeListMode, OnlyUpdateOperationMode, OriginalChangeListMode, TakesChangeList,
Unselected, UpdateOperationMode, Visibility,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UserOrVisibilityMode {
pub(super) visibility: Option<Visibility>,
pub(super) user: Option<String>,
}
impl ExclusiveOption for UserOrVisibilityMode {
fn inject_args(&self, command: &mut Command) {
if let Some(visibility) = &self.visibility {
command.arg("-t").arg(visibility.as_str());
}
if let Some(user) = &self.user {
command.arg("-U").arg(user);
}
}
}
impl TakesChangeList for UserOrVisibilityMode {}
#[doc(hidden)]
pub trait TransferUVMode {
type P;
type C;
fn transfer(self) -> (Self::P, Self::C);
}
impl TransferUVMode for (Unselected, Unselected) {
type P = Unselected;
type C = Unselected;
fn transfer(self) -> (Unselected, Unselected) {
(Unselected, Unselected)
}
}
impl TransferUVMode for (ForceOperationMode, Unselected) {
type P = OnlyForceOperationMode;
type C = Unselected;
fn transfer(self) -> (OnlyForceOperationMode, Unselected) {
(OnlyForceOperationMode, Unselected)
}
}
impl TransferUVMode for (UpdateOperationMode, Unselected) {
type P = OnlyUpdateOperationMode;
type C = Unselected;
fn transfer(self) -> (OnlyUpdateOperationMode, Unselected) {
(OnlyUpdateOperationMode, Unselected)
}
}
impl TransferUVMode for (Unselected, OriginalChangeListMode) {
type P = Unselected;
type C = OnlyOriginalChangeListMode;
fn transfer(self) -> (Unselected, OnlyOriginalChangeListMode) {
(Unselected, OnlyOriginalChangeListMode)
}
}
#[cfg(not(feature = "lt2022_1"))]
impl TransferUVMode for (Unselected, IdentityChangeListMode) {
type P = Unselected;
type C = OnlyIdentityChangeListMode;
fn transfer(self) -> (Unselected, OnlyIdentityChangeListMode) {
(Unselected, OnlyIdentityChangeListMode)
}
}
impl<O, C> Change<UserOrVisibilityMode, O, C, Unselected> {
pub fn user(mut self, user: impl Into<String>) -> Self {
self.mode.user = Some(user.into());
self
}
pub fn set_user(&mut self, user: impl Into<String>) -> &mut Self {
self.mode.user = Some(user.into());
self
}
pub fn get_user(&self) -> Option<&str> {
self.mode.user.as_deref()
}
pub fn visibility(mut self, visibility: Visibility) -> Self {
self.mode.visibility = Some(visibility);
self
}
pub fn set_visibility(&mut self, visibility: Visibility) -> &mut Self {
self.mode.visibility = Some(visibility);
self
}
pub fn get_visibility(&self) -> Option<Visibility> {
self.mode.visibility
}
}
impl Change<UserOrVisibilityMode, Unselected, Unselected, Unselected> {
#[cfg_attr(
not(feature = "lt2015_2"),
doc = "Mutually exclusive with `-u`, `-O`, and `-I`."
)]
#[cfg_attr(feature = "lt2015_2", doc = "Mutually exclusive with `-u` and `-O`.")]
pub fn force(
self,
) -> Change<UserOrVisibilityMode, OnlyForceOperationMode, Unselected, Unselected> {
Change {
bin: self.bin,
global_opts: self.global_opts,
mode: self.mode,
permission_mode: OnlyForceOperationMode,
changelist_mode: Unselected,
job_status_mode: Unselected,
}
}
#[cfg_attr(
not(feature = "lt2015_2"),
doc = "Mutually exclusive with `-f`, `-O`, and `-I`."
)]
#[cfg_attr(feature = "lt2015_2", doc = "Mutually exclusive with `-f` and `-O`.")]
pub fn update(
self,
) -> Change<UserOrVisibilityMode, OnlyUpdateOperationMode, Unselected, Unselected> {
Change {
bin: self.bin,
global_opts: self.global_opts,
mode: self.mode,
permission_mode: OnlyUpdateOperationMode,
changelist_mode: Unselected,
job_status_mode: Unselected,
}
}
#[cfg_attr(
not(feature = "lt2015_2"),
doc = "Mutually exclusive with `-f`, `-u`, and `-I`."
)]
#[cfg_attr(feature = "lt2015_2", doc = "Mutually exclusive with `-f` and `-u`.")]
pub fn original(
self,
) -> Change<UserOrVisibilityMode, Unselected, OnlyOriginalChangeListMode, Unselected> {
Change {
bin: self.bin,
global_opts: self.global_opts,
mode: self.mode,
permission_mode: Unselected,
changelist_mode: OnlyOriginalChangeListMode,
job_status_mode: Unselected,
}
}
#[cfg(not(feature = "lt2015_2"))]
pub fn identity(
self,
) -> Change<UserOrVisibilityMode, Unselected, OnlyIdentityChangeListMode, Unselected> {
Change {
bin: self.bin,
global_opts: self.global_opts,
mode: self.mode,
permission_mode: Unselected,
changelist_mode: OnlyIdentityChangeListMode,
job_status_mode: Unselected,
}
}
}