1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! The workflow layer's read door: `harness.v1.workflow.load`, the same code the `supercode
//! workflow load` verb calls. A harness's board is read as one typed [`Workflow`] value; the
//! board is written only through the harness's own door (`hermes kanban …`), never here.
use std::path::Path;
use serde::{Deserialize, Serialize};
use supercode_interchange::workflow::Workflow;
use crate::Result;
/// Which harness's board is read.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum WorkflowHarness {
/// Hermes's Kanban: `kanban/kanban.db` and `kanban/boards/<slug>/kanban.db` under the home.
Hermes,
/// supercode's own board, as its backing declares it (a `ztrack.json` marker beside the board's document).
Supercode,
}
impl WorkflowHarness {
/// The store a home's board is kept in, as the home declares it: a supercode board's marker, else a Hermes
/// `kanban.db`. A caller reads a board without naming its store.
pub fn of_home(home: &Path) -> Self {
let supercode = home.join("kanban").join("ztrack.json").is_file()
|| std::fs::read_dir(home.join("kanban").join("boards"))
.map(|entries| {
entries
.flatten()
.any(|entry| entry.path().join("ztrack.json").is_file())
})
.unwrap_or(false);
if supercode || !home.join("kanban.db").is_file() {
Self::Supercode
} else {
Self::Hermes
}
}
}
/// What a load answers.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorkflowRead {
/// The boards.
pub workflow: Workflow,
}
/// Read a harness's board as one workflow value.
pub fn load(from: WorkflowHarness, home: &Path) -> Result<WorkflowRead> {
let workflow = match from {
WorkflowHarness::Hermes => {
supercode_interchange::workflow::codec::hermes::from_hermes(home)?
}
WorkflowHarness::Supercode => {
supercode_interchange::workflow::codec::hermes::from_supercode(home)?
}
};
Ok(WorkflowRead { workflow })
}