Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ Phora reads `phora.toml` from the working directory, optionally overlaid by
[`phora.example.toml`](phora.example.toml) for a complete example.

```toml
version = 1
# version = 1 # optional; 1 is the only schema version and the default
# protocol = "ssh" # global default for forge sources (default https)

# [defaults]
Expand Down
2 changes: 1 addition & 1 deletion phora.example.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 1
# version = 1 # optional; 1 is the only schema version and the default

# protocol selects https vs ssh for host-aliased sources; default https.
# Uncomment to flip the global default (still overridable per source):
Expand Down
8 changes: 8 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,17 @@ impl Defaults {
}
}

/// The only schema version phora speaks; omitting `version` selects it.
pub const SCHEMA_VERSION: u32 = 1;

const fn default_schema_version() -> u32 {
SCHEMA_VERSION
}

#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
#[serde(default = "default_schema_version")]
pub version: u32,
Comment on lines +60 to 71
#[serde(default)]
pub protocol: Option<Protocol>,
Expand Down
8 changes: 8 additions & 0 deletions src/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ fn parses_version_and_all_sections_from_example() {
assert_eq!(cfg.targets.len(), 3);
}

#[test]
fn omitted_version_defaults_to_the_schema_version() {
let cfg = Config::parse("[sources.dots]\ngit = \"https://example.com/dots.git\"\n")
.expect("a config without a version key should parse");
assert_eq!(cfg.version, crate::config::SCHEMA_VERSION);
assert_eq!(cfg.sources.len(), 1);
}

#[test]
fn parses_source_fields_from_example() {
let cfg = Config::parse(EXAMPLE_TOML).expect("example toml should parse");
Expand Down
9 changes: 7 additions & 2 deletions tests/doc_invariants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,16 @@ fn local_example_toml_drops_legacy_binding_forms() {
fn readme_self_contained_fences_parse_and_validate() {
let complete: Vec<String> = fenced_blocks(README)
.into_iter()
.filter(|block| block.trim_start().starts_with("version = 1"))
.filter(|block| {
let lines: Vec<&str> = block.lines().collect();
lines.iter().any(|line| line.starts_with("[sources."))
&& lines.iter().any(|line| line.starts_with("[targets."))
})
Comment on lines +156 to +160
.collect();
assert!(
!complete.is_empty(),
"README.md: expected at least one self-contained `version = 1` config fence"
"README.md: expected at least one self-contained config fence declaring both \
a [sources.<s>] and a [targets.<t>] table"
);
for block in &complete {
let config = Config::parse(block).unwrap_or_else(|err| {
Expand Down