1use std::path::{Path, PathBuf};
2use crate::dirs::path_dir_storage;
3
4
5#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
6pub struct Profile {
7 name: String,
8}
9
10impl Profile {
11 pub const fn new(name: String) -> Self { Self { name } }
12
13 pub fn from_filename(filename: impl AsRef<str>) -> Option<Self> {
14 filename.as_ref().strip_prefix("credentials-")
15 .map(|name| Self::new(name.into()))
16 }
17
18 pub fn from_path(path: impl AsRef<Path>) -> Option<Self> {
19 Self::from_filename(path.as_ref().file_name()?.to_str()?)
20 }
21
22 pub fn filename(&self) -> String {
23 format!("credentials-{}", self.name)
24 }
25
26 pub const fn name(&self) -> &String { &self.name }
27
28 pub fn path(&self) -> Option<PathBuf> {
29 let mut path = path_dir_storage()?;
30 path.push(self.filename());
31 Some(path)
32 }
33}