(&self)
| 28 | |
| 29 | impl Command for Validate { |
| 30 | fn run(&self) -> CliResult<()> { |
| 31 | // Validation deliberately runs in the CLI process so neither the |
| 32 | // daemon nor shared libraries acquire the SHACL engine's MSRV. |
| 33 | let root = find_repository_root()?; |
| 34 | let snapshot = crate::commands::rpc::workflow_snapshot(&root)?; |
| 35 | let dot_dir = Repository::canonical_dot_dir(&root).map_err(CliError::Repository)?; |
| 36 | let error = |error: atomic_shacl::ValidationError| CliError::ShaclError(error.to_string()); |
| 37 | let data = |
| 38 | atomic_shacl::snapshot_ntriples(&snapshot.nodes, &snapshot.edges).map_err(error)?; |
| 39 | let request = atomic_shacl::ValidationRequest { |
| 40 | profile: match self.profile { |
| 41 | Profile::Projection => atomic_shacl::Profile::Projection, |
| 42 | Profile::Publication => atomic_shacl::Profile::Publication, |
| 43 | }, |
| 44 | shape: self.shape.clone(), |
| 45 | node: self.node.clone(), |
| 46 | custom: atomic_shacl::load_custom_shapes(&dot_dir.join("shapes")).map_err(error)?, |
| 47 | }; |
| 48 | let report = |
| 49 | atomic_shacl::validate_ntriples(&data, &snapshot.identity, &request).map_err(error)?; |
| 50 | match self.format { |
| 51 | Format::Json => println!( |
| 52 | "{}", |
| 53 | serde_json::to_string_pretty(&report) |
| 54 | .map_err(|error| CliError::Internal(error.into()))? |
| 55 | ), |
| 56 | Format::Text => { |
| 57 | println!( |
| 58 | "SHACL {:?}: {}", |
| 59 | report.profile, |
| 60 | if report.conforms { |
| 61 | "conforms" |
| 62 | } else { |
| 63 | "violations" |
| 64 | } |
| 65 | ); |
| 66 | println!( |
| 67 | "Snapshot: {}\nProfile: {}", |
| 68 | report.snapshot_identity, report.profile_identity |
| 69 | ); |
| 70 | for coverage in &report.target_coverage { |
| 71 | println!( |
| 72 | " {}: {} evaluated / {} applicable", |
| 73 | coverage.shape, coverage.evaluated, coverage.applicable |
| 74 | ); |
| 75 | } |
| 76 | for result in &report.results { |
| 77 | println!( |
| 78 | " {} {}: {} (path {}, shape {}, component {})", |
| 79 | result["result_severity"], |
| 80 | result["focus_node"], |
| 81 | result["result_messages"], |
| 82 | result["result_path"], |
| 83 | result["source_shape"], |
| 84 | result["source_constraint_component"] |
| 85 | ); |
| 86 | } |
| 87 | for diagnostic in &report.diagnostics { |
nothing calls this directly
no test coverage detected