cedar_policy_cli/command/visualize.rs
1/*
2 * Copyright Cedar Contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use clap::Args;
18
19use crate::{load_entities, CedarExitCode};
20
21#[derive(Args, Debug)]
22pub struct VisualizeArgs {
23 #[arg(long = "entities", value_name = "FILE")]
24 pub entities_file: String,
25}
26
27pub fn visualize(args: &VisualizeArgs) -> CedarExitCode {
28 match load_entities(&args.entities_file, None) {
29 Ok(entities) => {
30 println!("{}", entities.to_dot_str());
31 CedarExitCode::Success
32 }
33 Err(report) => {
34 eprintln!("{report:?}");
35 CedarExitCode::Failure
36 }
37 }
38}