Skip to content

Commit b075077

Browse files
committed
Add: meta options struct for schema file cmdline args take precendence
1 parent de72405 commit b075077

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "faking"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
edition = "2021"
55
description = "faking is a cli tool that generates test data in various formats from a given schema"
66
license = "MPL-2.0"

schemas/testcase.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"meta": {
3+
"number": 1
4+
},
25
"schema": [
36
{
47
"field_name": "field-1-bool",

src/json_reader/obj.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ pub struct Obj {
1616
pub fields: Vec<FieldsEnum>
1717
}
1818

19+
#[derive(Serialize, Deserialize, Debug)]
20+
pub struct MetaObj {
21+
pub output: Option<String>,
22+
pub number: Option<i64>,
23+
}
24+
1925
#[derive(Serialize, Deserialize, Debug)]
2026
pub struct DTObj {
21-
// meta: Option<MetaObj>,
27+
pub meta: Option<MetaObj>,
2228
pub schema: Vec<FieldsEnum>
2329
}

src/main.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,35 @@ fn main() -> Result<(), std::io::Error> {
132132
Err(error) => return Err(error),
133133
};
134134

135+
let mut n_rows = DEFAULT_GEN_AMOUNT;
136+
137+
match struct_res.meta.as_ref() {
138+
Some(meta) => match meta.number {
139+
Some(number) => {
140+
n_rows = number;
141+
142+
if n_rows < 1 {
143+
n_rows = 1
144+
}
145+
}
146+
None => {}
147+
},
148+
149+
None => {}
150+
}
151+
135152
match cli.n {
136153
Some(val) => {
137-
let mut n = val;
138-
if n < 1 {
139-
n = 1
154+
n_rows = val;
155+
if n_rows < 1 {
156+
n_rows = 1
140157
}
141-
142-
generate_json_output(&struct_res, n);
143-
}
144-
None => {
145-
generate_json_output(&struct_res, DEFAULT_GEN_AMOUNT);
146158
}
159+
160+
None => {}
147161
}
162+
163+
generate_json_output(&struct_res, n_rows);
148164
}
149165

150166
return Ok(());

0 commit comments

Comments
 (0)