Skip to main content

Repository

Struct Repository 

Source
pub struct Repository { /* private fields */ }
Expand description

A repository of Architecture Decision Records.

Implementations§

Source§

impl Repository

Source

pub fn open(root: impl Into<PathBuf>) -> Result<Self>

Open an existing repository at the given root.

Source

pub fn open_or_default(root: impl Into<PathBuf>) -> Self

Open a repository, or create default config if not found.

Source

pub fn init( root: impl Into<PathBuf>, adr_dir: Option<PathBuf>, ng: bool, ) -> Result<Self>

Initialize a new repository at the given root.

If a config file (adrs.toml or .adr-dir) already exists at root and its configured adr_dir already matches the resolved directory, the file is left untouched – including settings this function does not otherwise know about, such as default_status, templates, generate, export, and doctor. Otherwise a fresh config is written for the resolved directory and mode, as before.

Source

pub fn root(&self) -> &Path

Get the repository root path.

Source

pub fn config(&self) -> &Config

Get the configuration.

Source

pub fn adr_path(&self) -> PathBuf

Get the full path to the ADR directory.

Source

pub fn with_template_format(self, format: TemplateFormat) -> Self

Set the template format.

Source

pub fn with_template_variant(self, variant: TemplateVariant) -> Self

Set the template variant.

Source

pub fn with_mode(self, mode: ConfigMode) -> Self

Override the configuration mode.

Source

pub fn with_custom_template(self, template: Template) -> Self

Set a custom template.

Source

pub fn list(&self) -> Result<Vec<Adr>>

List all ADRs in the repository.

Source

pub fn list_with_errors(&self) -> Result<(Vec<Adr>, Vec<(PathBuf, Error)>)>

List all ADRs, also returning parse errors for files that look like ADRs but failed to parse.

This is used by the doctor command to report files that could not be parsed (e.g., invalid frontmatter).

Source

pub fn next_number(&self) -> Result<u32>

Get the next available ADR number.

Source

pub fn get(&self, number: u32) -> Result<Adr>

Find an ADR by number.

Source

pub fn find(&self, query: &str) -> Result<Adr>

Find an ADR by query (number or fuzzy title match).

Source

pub fn create(&self, adr: &Adr) -> Result<PathBuf>

Create a new ADR.

Source

pub fn new_adr(&self, title: impl Into<String>) -> Result<(Adr, PathBuf)>

Create a new ADR with the given title.

Source

pub fn supersede( &self, title: impl Into<String>, superseded: u32, ) -> Result<(Adr, PathBuf)>

Create a new ADR that supersedes another.

Source

pub fn set_status( &self, number: u32, status: AdrStatus, superseded_by: Option<u32>, ) -> Result<PathBuf>

Change the status of an ADR.

If the new status is Superseded and superseded_by is provided, a superseded-by link will be added automatically.

Link two ADRs together.

Source

pub fn renumber( &self, from: u32, to: u32, file: Option<&Path>, dry_run: bool, ) -> Result<RenumberResult>

Repair a duplicate or misassigned ADR number by moving from to to.

Renumbering touches four things and gets all four right in a single pass: the filename, the record’s own frontmatter number (nextgen) and H1 heading, and every other record’s inbound reference to it (frontmatter links[].target and rendered body markdown links). Records are edited surgically in place – never re-rendered from a template – so hand-written content that doesn’t round-trip through the template survives (see #310).

§Preconditions (checked before any write)
  1. from is resolved via Self::list, not Self::get, because get silently returns only the first match for a number and the motivating scenario is a duplicate number. Zero matches is an error. More than one match with no file given is an error listing every candidate path. If file is given, it must match one of the candidates.
  2. from == to is a no-op: returns immediately with RenumberResult::no_op set, before any occupancy check.
  3. to must be free. If occupied, the error names the occupying record and suggests the smallest free number.
§Writes

When dry_run is false and every precondition passes: the file is renamed, the record’s own frontmatter number and H1 are updated, and every other record whose frontmatter links or body markdown links reference the old number/filename are rewritten. A record with no reference to from at all is left byte-for-byte untouched. CRLF line endings are preserved throughout (see #339/#340).

After a successful renumber (dry run or not), the rest of the repository root is scanned for the old filename outside the ADR directory (skipping .git, target, node_modules); matches are reported in RenumberResult::prose_warnings but never rewritten.

With dry_run: true, nothing on disk changes; the returned RenumberResult describes exactly what would have happened.

Source

pub fn update(&self, adr: &Adr, body: BodySectionPatch) -> Result<PathBuf>

Update an existing ADR.

When body is non-empty, only the listed body sections are patched in place; metadata bytes on disk are left unchanged. When body is empty, metadata (status, links, tags, and MADR 4.0.0 frontmatter fields) is updated via the same path as Self::update_metadata.

Empty body does not re-render context/decision/consequences from adr (unlike the pre-BodySectionPatch API). Mutating those fields on adr and calling update(&adr, BodySectionPatch::default()) writes metadata only; body text on disk is unchanged. Pass the new text in body to patch sections.

adr.title and adr.date are not written by this method.

Unlisted body sections are left byte-for-byte unchanged on disk, including MADR ### Consequences / ### Confirmation subsections under ## Decision Outcome.

Source

pub fn read_content(&self, adr: &Adr) -> Result<String>

Read the content of an ADR file.

Source

pub fn write_content(&self, adr: &Adr, content: &str) -> Result<PathBuf>

Write content to an ADR file.

Source

pub fn update_metadata(&self, adr: &Adr) -> Result<PathBuf>

Update only the metadata (status, links, tags) of an existing ADR file, preserving all other content byte-for-byte.

Trait Implementations§

Source§

impl Debug for Repository

Source§

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

Formats the value using the given formatter. Read more

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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.