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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#![deny(missing_docs)]
//! This crate provides functionality to compare JSON files
use std::path::PathBuf;
use clap::Parser;
#[derive(Parser)]
#[command(version, about)]
/// Defines the command line arguments that can be used with this program
pub enum Options {
#[command(alias = "v")]
/// Checks whether the keys in the source file/directory align with the base file
Verify {
/// This file will be used as base template for every source file
base: PathBuf,
/// This can be a file or directory. It will be checked against the base
source: PathBuf,
/// Wether to explore the specified source directory recursivly or not
/// This has no effect when source is a file
#[arg(long, short, default_value_t = false)]
recursive: bool,
/// When this flag is set, the order is also considered while validating
#[arg(long, short, default_value_t = false)]
strict: bool,
},
/// Checks whether the used templates in the source file/directory align with the base file
#[command(alias = "vt")]
VerifyTemplates {
/// This file will be used as base template for every source file
base: PathBuf,
/// This can be a file or directory. It will be checked against the base
source: PathBuf,
/// Wether to explore the specified source directory recursivly or not
/// This has no effect when source is a file
#[arg(long, short, default_value_t = false)]
recursive: bool,
},
/// Sorts the keys in source based on the order used in base
#[command(alias = "s")]
Sort {
/// This file will be used as base template for every source file
base: PathBuf,
/// This can be a file or directory. It will be checked against the base
source: PathBuf,
/// Wether to explore the specified source directory recursivly or not
/// This has no effect when source is a file
#[arg(long, short, default_value_t = false)]
recursive: bool,
/// When supplied, the output will be written to this file instead of stdout.
#[arg(long, short)]
output: Option<PathBuf>,
/// When this flag is set, the order will only be applied if both source and base have the
/// exact same keys.
#[arg(long, short, default_value_t = false)]
strict: bool,
},
/// This will find all differences between base and source
#[command(alias = "d")]
Diff {
/// This file will be used as base template for every source file
base: PathBuf,
/// This can be a file or directory. It will be checked against the base
source: PathBuf,
/// Wether to explore the specified source directory recursivly or not
/// This has no effect when source is a file
#[arg(long, short, default_value_t = false)]
recursive: bool,
/// When this flag is active the source will be extended/trimmed based on the base.
/// If not supplied, a report will be printed, what is more or missing based on the base.
#[arg(long, short, default_value_t = false)]
fix: bool,
/// When supplied, the output will be written to this file instead of stdout.
#[arg(long, short)]
output: Option<PathBuf>,
},
}
fn main() {
let options = Options::parse();
match options {
Options::Diff {
base,
source,
fix,
output,
recursive,
} => diff::diff(base, source, recursive, fix, output),
Options::Verify {
base,
source,
recursive,
strict,
} => verify::verify(base, source, recursive, strict),
Options::VerifyTemplates {
base,
source,
recursive,
} => verify_templates::verify_templates(base, source, recursive),
Options::Sort {
base,
source,
recursive,
output,
strict,
} => sort::sort(base, source, recursive, output, strict),
}
}
mod diff;
mod sort;
mod utility;
mod verify;
mod verify_templates;