Skip to main content

Profiles

Struct Profiles 

Source
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: String

The 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

Source

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");
Source

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());
Source

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}");
Source

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"));
Source

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§

Source§

impl Clone for Profiles

Source§

fn clone(&self) -> Profiles

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Profiles

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Profiles

Source§

fn default() -> Profiles

Returns the “default value” for a type. Read more
Source§

impl Eq for Profiles

Source§

impl PartialEq for Profiles

Source§

fn eq(&self, other: &Profiles) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Profiles

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more