dev_scope/shared/
mod.rs

1use colored::Colorize;
2
3use crate::models::HelpMetadata;
4use std::cmp::max;
5use std::path::Path;
6use tracing::info;
7
8mod capture;
9mod config_load;
10mod logging;
11// mod models_bck;
12mod models;
13mod redact;
14mod report;
15
16pub const CONFIG_FILE_PATH_ENV: &str = "SCOPE_CONFIG_JSON";
17pub const RUN_ID_ENV_VAR: &str = "SCOPE_RUN_ID";
18
19pub mod prelude {
20    pub use super::capture::{
21        CaptureError, CaptureOpts, DefaultExecutionProvider, ExecutionProvider,
22        MockExecutionProvider, OutputCapture, OutputCaptureBuilder, OutputDestination,
23    };
24    pub use super::config_load::{build_config_path, ConfigOptions, FoundConfig};
25    pub use super::logging::LoggingOpts;
26    pub use super::models::prelude::*;
27    pub use super::print_details;
28    pub use super::report::ReportBuilder;
29    pub use super::{CONFIG_FILE_PATH_ENV, RUN_ID_ENV_VAR};
30}
31
32pub(crate) fn convert_to_string(input: Vec<&str>) -> Vec<String> {
33    input.iter().map(|x| x.to_string()).collect()
34}
35
36pub fn print_details<T>(working_dir: &Path, config: &Vec<T>)
37where
38    T: HelpMetadata,
39{
40    let max_name_length = config
41        .iter()
42        .map(|x| x.full_name().len())
43        .max()
44        .unwrap_or(20);
45    let max_name_length = max(max_name_length, 20) + 2;
46
47    info!(target: "user", "  {:max_name_length$}{:60}{}", "Name".white().bold(), "Description".white().bold(), "Path".white().bold());
48    for resource in config {
49        let mut description = resource.description().to_string();
50        if description.len() > 55 {
51            description.truncate(55);
52            description = format!("{}...", description);
53        }
54
55        let mut loc = resource.metadata().file_path();
56        let diff_path = pathdiff::diff_paths(&loc, working_dir);
57        if let Some(diff) = diff_path {
58            loc = diff.display().to_string();
59        } else if loc.len() > 35 {
60            loc = format!("...{}", loc.split_off(loc.len() - 35));
61        }
62
63        info!(target: "user", "- {:max_name_length$}{:60}{}", resource.full_name(), description, loc);
64    }
65}