Skip to main content

transition

Function transition 

Source
pub fn transition(
    root: &Path,
    path: &Path,
    index: &Index,
    plan: &Plan,
    id: &str,
    transition: Transition,
    now: &str,
    vocabulary: &Vocabulary,
    git: &GitState,
) -> Result<(), TransitionError>
Expand description

Perform one transition: check it, stamp the record, append the event.

The order is the shell’s and is not an implementation detail. The guard runs against the plan as it reads now; the record is rewritten; only then is the event appended. A ledger line therefore never describes a change that did not reach the file, which is the property that lets the record be read as history rather than as intent.

path is the issue’s own file, as the index recorded it. It is passed in rather than derived from the id here, because the index already knows where every record lives and a second convention for locating one is how two readers come to disagree about which file is the record.

use majordomus_cli::ledger::{self, Vocabulary};
use majordomus_cli::plan::{transition, Plan, Transition};
let plan = Plan::build(index);
let vocabulary = Vocabulary::load(&root.join("share/events.yaml")).unwrap();
let at = ledger::now();
// The guard runs first, the record is rewritten, and only then is the event appended:
// a ledger line never describes a change that did not reach the file.
transition(root, record, index, &plan, "I0001", Transition::Start, &at, &vocabulary, git)
    .expect("a READY issue may start");