Skip to content

Commit 6561052

Browse files
committed
Merge branch 'validation-issue-11'
2 parents 83a6563 + 8c051d3 commit 6561052

File tree

4 files changed

+864
-4
lines changed

4 files changed

+864
-4
lines changed

src/cmd_line.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,19 @@ pub fn get_args() -> ArgMatches<'static> {
5959
.multiple(true)
6060
.help("Create a reference module"),
6161
)
62-
// This group ensures that at least one of the assembly or module inputs is present
62+
.arg(
63+
Arg::with_name("validate")
64+
.short("l")
65+
.long("validate")
66+
.takes_value(true)
67+
.value_name("file")
68+
.multiple(true)
69+
.help("Validate (lint) an existing module or assembly file")
70+
)
71+
// This group specifies that you either generate modules or validate existing ones
6372
.group(
64-
ArgGroup::with_name("modules")
65-
.args(&["assembly", "concept", "procedure", "reference"])
73+
ArgGroup::with_name("required")
74+
.args(&["assembly", "concept", "procedure", "reference", "validate"])
6675
.required(true)
6776
.multiple(true),
6877
)

src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod cmd_line;
44
mod logging;
55
mod module;
66
mod templating;
7+
mod validation;
78
mod write;
89

910
use module::{Input, Module, ModuleType};
@@ -97,6 +98,13 @@ fn main() {
9798

9899
populated.write_file(&options);
99100
}
101+
102+
// Validate all file names specified on the command line
103+
if let Some(files_iterator) = cmdline_args.values_of("validate") {
104+
for file in files_iterator {
105+
validation::validate(file);
106+
}
107+
}
100108
}
101109

102110
/// Process all titles that have been specified on the command line and that belong to a single

src/module.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use log::debug;
21
/// This module defines the `Module` struct, its builder struct, and methods on both structs.
2+
use log::debug;
3+
use std::fmt;
34
use std::path::{Path, PathBuf};
45

56
use crate::Options;
@@ -13,6 +14,19 @@ pub enum ModuleType {
1314
Reference,
1415
}
1516

17+
// Implement human-readable string display for the module type
18+
impl fmt::Display for ModuleType {
19+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20+
let name = match self {
21+
Self::Assembly => "assembly",
22+
Self::Concept => "concept",
23+
Self::Procedure => "procedure",
24+
Self::Reference => "reference",
25+
};
26+
write!(f, "{}", name)
27+
}
28+
}
29+
1630
/// An initial representation of the module with input data, used to construct the `Module` struct
1731
#[derive(Debug)]
1832
pub struct Input {

0 commit comments

Comments
 (0)