pub struct Profiles {
pub default: String,
pub binary_extensions: BTreeSet<String>,
pub artifact_paths: Vec<String>,
pub profiles: Vec<PackProfile>,
}Expand description
What the distribution declares once for every profile: the default, the binary extensions, the artifact paths, and the profiles themselves.
use majordomus_cli::pack::Profiles;
let p = Profiles::parse(
"default: a\nbinary_extensions: [\"PNG\"]\nprofiles:\n - id: a\n - id: b\n",
)
.unwrap();
assert_eq!(p.default, "a");
assert!(p.binary_extensions.contains("png"), "extensions are compared in lower case");
assert_eq!(p.profiles.len(), 2);Fields§
§default: StringThe profile used when none is named.
binary_extensions: BTreeSet<String>Extensions, without the dot, that are binary whatever their content.
artifact_paths: Vec<String>Globs of build output, caches and worktree containers.
profiles: Vec<PackProfile>Every profile, in file order.
Implementations§
Source§impl Profiles
impl Profiles
Sourcepub fn load(share: &Path, root: &Path) -> Result<Profiles, String>
pub fn load(share: &Path, root: &Path) -> Result<Profiles, String>
Read the profiles from the share directory, then the repository’s overlay
(.ai/repo/archive.yaml), whose profiles replace the shipped ones of the same id.
use majordomus_cli::pack::Profiles;
let dir = tempfile::tempdir().unwrap();
let (share, root) = (dir.path().join("share"), dir.path().join("repo"));
std::fs::create_dir_all(&share).unwrap();
std::fs::create_dir_all(root.join(".ai/repo")).unwrap();
std::fs::write(share.join("archive.yaml"), "default: a\nprofiles:\n - id: a\n").unwrap();
std::fs::write(
root.join(".ai/repo/archive.yaml"),
"profiles:\n - id: a\n title: ours\n",
)
.unwrap();
let p = Profiles::load(&share, &root).unwrap();
assert_eq!(p.profile(None).unwrap().title, "ours");
assert!(Profiles::load(&root, &root).is_err(), "no archive.yaml there");Sourcepub fn parse(text: &str) -> Result<Profiles, String>
pub fn parse(text: &str) -> Result<Profiles, String>
Parse the text of a profiles file, without the overlay: the default, the two lists
and the profiles, with extensions lowered so that PNG and png are one.
use majordomus_cli::pack::Profiles;
let p = Profiles::parse("default: a\nprofiles:\n - id: a\n exclude: [\"x/**\"]\n").unwrap();
assert_eq!(p.profile(None).unwrap().id, "a");
assert!(p.profile(Some("b")).is_err());Sourcepub fn profile(&self, id: Option<&str>) -> Result<&PackProfile, String>
pub fn profile(&self, id: Option<&str>) -> Result<&PackProfile, String>
The named profile, or the default one when no name is given; an unknown name is an error that lists the profiles there are.
use majordomus_cli::pack::Profiles;
let p = Profiles::parse("default: a\nprofiles:\n - id: a\n - id: b\n").unwrap();
assert_eq!(p.profile(Some("b")).unwrap().id, "b");
let e = p.profile(Some("c")).unwrap_err();
assert!(e.contains("a, b"), "{e}");Sourcepub fn is_artifact(&self, path: &str) -> bool
pub fn is_artifact(&self, path: &str) -> bool
Is path one of the distribution’s artifact paths: build output, a cache or a
worktree container that was committed by accident?
use majordomus_cli::pack::Profiles;
let p = Profiles::parse(
"default: a\nartifact_paths: [\"**/target/**\"]\nprofiles:\n - id: a\n",
)
.unwrap();
assert!(p.is_artifact("apps/x/target/debug/y.rs"));
assert!(!p.is_artifact("apps/x/src/target.rs"));Sourcepub fn has_binary_extension(&self, path: &str) -> bool
pub fn has_binary_extension(&self, path: &str) -> bool
Does path carry an extension on the binary list? The extension is the file name’s
last, compared in lower case; a dot file such as .png has none.
use majordomus_cli::pack::Profiles;
let p = Profiles::parse("default: a\nbinary_extensions: [png]\nprofiles:\n - id: a\n")
.unwrap();
assert!(p.has_binary_extension("site/logo.PNG"));
assert!(!p.has_binary_extension("dir.png/readme.md"));
assert!(!p.has_binary_extension(".png"));Trait Implementations§
impl Eq for Profiles
impl StructuralPartialEq for Profiles
Auto Trait Implementations§
impl Freeze for Profiles
impl RefUnwindSafe for Profiles
impl Send for Profiles
impl Sync for Profiles
impl Unpin for Profiles
impl UnsafeUnpin for Profiles
impl UnwindSafe for Profiles
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.