clean up
This commit is contained in:
@@ -43,13 +43,15 @@ pub fn run(args: Cli) -> Result<()> {
|
||||
let renderer = create_renderer(&args.format, level, !args.no_weights)?;
|
||||
|
||||
if args.check {
|
||||
let existing_path = args.output.as_ref()
|
||||
.ok_or_else(|| anyhow::anyhow!("--check requires --output to specify the file to check against"))?;
|
||||
let existing_path = args.output.as_ref().ok_or_else(|| {
|
||||
anyhow::anyhow!("--check requires --output to specify the file to check against")
|
||||
})?;
|
||||
let up_to_date = CheckFreshness {
|
||||
graph: &graph,
|
||||
renderer: &*renderer,
|
||||
existing_path: std::path::Path::new(existing_path),
|
||||
}.execute()?;
|
||||
}
|
||||
.execute()?;
|
||||
if up_to_date {
|
||||
println!("Architecture diagram is up to date.");
|
||||
} else {
|
||||
@@ -60,8 +62,14 @@ pub fn run(args: Cli) -> Result<()> {
|
||||
}
|
||||
|
||||
let (raw_allow, raw_deny) = config_loader.load_rules();
|
||||
let allow: Vec<BoundaryRule> = raw_allow.iter().filter_map(|s| BoundaryRule::parse(s)).collect();
|
||||
let deny: Vec<BoundaryRule> = raw_deny.iter().filter_map(|s| BoundaryRule::parse(s)).collect();
|
||||
let allow: Vec<BoundaryRule> = raw_allow
|
||||
.iter()
|
||||
.filter_map(|s| BoundaryRule::parse(s))
|
||||
.collect();
|
||||
let deny: Vec<BoundaryRule> = raw_deny
|
||||
.iter()
|
||||
.filter_map(|s| BoundaryRule::parse(s))
|
||||
.collect();
|
||||
let output_dir = args.output.as_ref().map(std::path::PathBuf::from);
|
||||
|
||||
let use_case = GenerateDiagram {
|
||||
@@ -76,7 +84,10 @@ pub fn run(args: Cli) -> Result<()> {
|
||||
|
||||
let violations = use_case.check_violations_only();
|
||||
if args.strict && !violations.is_empty() {
|
||||
bail!("{} boundary rule violation(s) in strict mode", violations.len());
|
||||
bail!(
|
||||
"{} boundary rule violation(s) in strict mode",
|
||||
violations.len()
|
||||
);
|
||||
}
|
||||
use_case.execute()?;
|
||||
|
||||
@@ -135,10 +146,18 @@ fn build_graph(args: &Cli, level: DiagramLevel) -> Result<NormalizedGraph> {
|
||||
|
||||
if !result.warnings().is_empty() {
|
||||
for warning in result.warnings() {
|
||||
eprintln!("WARNING: {}:{} {}", warning.file_path().as_str(), warning.line(), warning.message());
|
||||
eprintln!(
|
||||
"WARNING: {}:{} {}",
|
||||
warning.file_path().as_str(),
|
||||
warning.line(),
|
||||
warning.message()
|
||||
);
|
||||
}
|
||||
if args.strict {
|
||||
bail!("analysis produced {} warning(s) in strict mode", result.warnings().len());
|
||||
bail!(
|
||||
"analysis produced {} warning(s) in strict mode",
|
||||
result.warnings().len()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +184,9 @@ fn create_renderer(
|
||||
show_weights: bool,
|
||||
) -> Result<Box<dyn archlens_domain::ports::DiagramRenderer>> {
|
||||
match format {
|
||||
"mermaid" => Ok(Box::new(MermaidRenderer::with_level(level).with_weights(show_weights))),
|
||||
"mermaid" => Ok(Box::new(
|
||||
MermaidRenderer::with_level(level).with_weights(show_weights),
|
||||
)),
|
||||
"ascii" => Ok(Box::new(AsciiRenderer::new())),
|
||||
"d2" => Ok(Box::new(D2Renderer::with_level(level))),
|
||||
"html" => Ok(Box::new(HtmlRenderer::new())),
|
||||
@@ -193,7 +214,8 @@ fn run_diff(args: &Cli, existing_path: &std::path::Path) -> Result<()> {
|
||||
graph: &graph,
|
||||
renderer: &*renderer,
|
||||
existing_path,
|
||||
}.execute()?;
|
||||
}
|
||||
.execute()?;
|
||||
|
||||
if diff.is_empty() {
|
||||
println!("No changes detected.");
|
||||
@@ -206,7 +228,11 @@ fn run_diff(args: &Cli, existing_path: &std::path::Path) -> Result<()> {
|
||||
for line in &diff.added {
|
||||
println!("{line}");
|
||||
}
|
||||
println!("\n{} added, {} removed", diff.added.len(), diff.removed.len());
|
||||
println!(
|
||||
"\n{} added, {} removed",
|
||||
diff.added.len(),
|
||||
diff.removed.len()
|
||||
);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
@@ -286,7 +312,10 @@ fn get_changed_files(
|
||||
.map_err(|e| anyhow::anyhow!("git not found: {e}"))?;
|
||||
|
||||
if !output.status.success() {
|
||||
bail!("git diff failed: {}", String::from_utf8_lossy(&output.stderr));
|
||||
bail!(
|
||||
"git diff failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
|
||||
let files = String::from_utf8_lossy(&output.stdout)
|
||||
@@ -324,8 +353,14 @@ fn run_watch(args: Cli) -> Result<()> {
|
||||
}
|
||||
|
||||
let (raw_allow, raw_deny) = config_loader.load_rules();
|
||||
let allow: Vec<BoundaryRule> = raw_allow.iter().filter_map(|s| BoundaryRule::parse(s)).collect();
|
||||
let deny: Vec<BoundaryRule> = raw_deny.iter().filter_map(|s| BoundaryRule::parse(s)).collect();
|
||||
let allow: Vec<BoundaryRule> = raw_allow
|
||||
.iter()
|
||||
.filter_map(|s| BoundaryRule::parse(s))
|
||||
.collect();
|
||||
let deny: Vec<BoundaryRule> = raw_deny
|
||||
.iter()
|
||||
.filter_map(|s| BoundaryRule::parse(s))
|
||||
.collect();
|
||||
if !allow.is_empty() || !deny.is_empty() {
|
||||
let use_case = GenerateDiagram {
|
||||
graph,
|
||||
@@ -343,7 +378,10 @@ fn run_watch(args: Cli) -> Result<()> {
|
||||
Ok(())
|
||||
};
|
||||
|
||||
eprintln!("Watching {} for changes (Ctrl+C to stop)...", args.path.display());
|
||||
eprintln!(
|
||||
"Watching {} for changes (Ctrl+C to stop)...",
|
||||
args.path.display()
|
||||
);
|
||||
if let Err(e) = run_once(&args) {
|
||||
eprintln!("Error: {e}");
|
||||
} else {
|
||||
@@ -351,14 +389,18 @@ fn run_watch(args: Cli) -> Result<()> {
|
||||
}
|
||||
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let mut watcher = recommended_watcher(move |res| { let _ = tx.send(res); })?;
|
||||
let mut watcher = recommended_watcher(move |res| {
|
||||
let _ = tx.send(res);
|
||||
})?;
|
||||
watcher.watch(&args.path, RecursiveMode::Recursive)?;
|
||||
|
||||
let mut last_run = Instant::now();
|
||||
loop {
|
||||
match rx.recv() {
|
||||
Ok(_) => {
|
||||
if last_run.elapsed() < debounce { continue; }
|
||||
if last_run.elapsed() < debounce {
|
||||
continue;
|
||||
}
|
||||
last_run = Instant::now();
|
||||
eprintln!("Change detected, regenerating...");
|
||||
if let Err(e) = run_once(&args) {
|
||||
@@ -367,7 +409,10 @@ fn run_watch(args: Cli) -> Result<()> {
|
||||
eprintln!("Diagram updated.");
|
||||
}
|
||||
}
|
||||
Err(e) => { eprintln!("Watch error: {e}"); break; }
|
||||
Err(e) => {
|
||||
eprintln!("Watch error: {e}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user