git-next/crates/config/src/forge_details.rs

47 lines
1.2 KiB
Rust
Raw Normal View History

use crate::{ApiToken, ForgeConfig, ForgeName, ForgeType, Hostname, User};
/// The derived information about a Forge, used to create interactions with it
#[derive(Clone, Debug, derive_more::Constructor)]
pub struct ForgeDetails {
forge_name: ForgeName,
forge_type: ForgeType,
hostname: Hostname,
user: User,
token: ApiToken,
// API Token
// Private SSH Key Path
}
impl ForgeDetails {
pub const fn forge_name(&self) -> &ForgeName {
&self.forge_name
}
pub const fn forge_type(&self) -> ForgeType {
self.forge_type
}
pub const fn hostname(&self) -> &Hostname {
&self.hostname
}
pub const fn user(&self) -> &User {
&self.user
}
pub const fn token(&self) -> &ApiToken {
&self.token
}
pub fn with_hostname(self, hostname: Hostname) -> Self {
let mut me = self;
me.hostname = hostname;
me
}
}
impl From<(&ForgeName, &ForgeConfig)> for ForgeDetails {
fn from(forge: (&ForgeName, &ForgeConfig)) -> Self {
Self {
forge_name: forge.0.clone(),
forge_type: forge.1.forge_type(),
hostname: forge.1.hostname(),
user: forge.1.user(),
token: forge.1.token(),
}
}
}