Skip to content

Commit da5a565

Browse files
committed
api+json: Create pdu field
resolve #28
1 parent 3243d2d commit da5a565

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/app/sub.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
args::Fraction,
33
data_tree::{DataTree, DataTreeReflection},
44
fs_tree_builder::FsTreeBuilder,
5-
json_data::{JsonData, SchemaVersion, UnitAndTree},
5+
json_data::{BinaryVersion, JsonData, SchemaVersion, UnitAndTree},
66
os_string_display::OsStringDisplay,
77
reporter::ParallelReporter,
88
runtime_error::RuntimeError,
@@ -123,6 +123,7 @@ where
123123
.into();
124124
let json_data = JsonData {
125125
schema_version: SchemaVersion,
126+
binary_version: Some(BinaryVersion::current()),
126127
unit_and_tree,
127128
};
128129
return serde_json::to_writer(stdout(), &json_data)

src/json_data.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
pub mod binary_version;
12
pub mod schema_version;
23

4+
pub use binary_version::BinaryVersion;
35
pub use schema_version::SchemaVersion;
46

57
use crate::{
@@ -31,6 +33,9 @@ pub enum UnitAndTree {
3133
pub struct JsonData {
3234
/// The `"schema-version"` field.
3335
pub schema_version: SchemaVersion,
36+
/// The `"pdu"` field.
37+
#[cfg_attr(feature = "json", serde(rename = "pdu"))]
38+
pub binary_version: Option<BinaryVersion>,
3439
/// The `"unit"` field and the `"tree"` field.
3540
#[cfg_attr(feature = "json", serde(flatten))]
3641
pub unit_and_tree: UnitAndTree,

src/json_data/binary_version.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use derive_more::{AsMut, AsRef, From, FromStr, Into};
2+
3+
#[cfg(feature = "json")]
4+
use serde::{Deserialize, Serialize};
5+
6+
/// Version of the current `pdu` program.
7+
pub const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION");
8+
9+
/// Version of the `pdu` program that created the input JSON.
10+
#[derive(Debug, Clone, PartialEq, Eq, AsMut, AsRef, From, FromStr, Into)]
11+
#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
12+
pub struct BinaryVersion(String);
13+
14+
impl BinaryVersion {
15+
/// Get version of the current `pdu` program as a `BinaryVersion`.
16+
pub fn current() -> Self {
17+
CURRENT_VERSION.to_string().into()
18+
}
19+
}

0 commit comments

Comments
 (0)