workspacer_show/
show_all.rs

1// ---------------- [ File: workspacer-show/src/show_all.rs ]
2crate::ix!();
3
4#[async_trait]
5pub trait ShowAll {
6
7    type Error;
8
9    async fn show_all(&self, options: &ShowFlags) -> Result<String, Self::Error>;
10}
11
12#[async_trait]
13impl<P, H> ShowAll for Workspace<P, H>
14where
15    for<'a> P: From<PathBuf> + AsRef<Path> + Clone + Send + Sync + 'a,
16    for<'a> H: CrateHandleInterface<P> + ShowItem<Error = CrateError> + Send + Sync + 'a,
17{
18    type Error = WorkspaceError;
19
20    #[tracing::instrument(level = "trace", skip(self, options))]
21    async fn show_all(&self, options: &ShowFlags) -> Result<String, Self::Error> {
22        trace!("Entering ShowWorkspace::show_workspace at path={:?}", self.as_ref());
23
24        // We'll accumulate the final output across all crates
25        let mut output = String::new();
26
27        let crates_list = self.crates();
28        if crates_list.is_empty() && *options.show_items_with_no_data() {
29            return Ok("<no-data-for-crate>\n".to_string());
30        }
31
32        // For each crate:
33        for crate_arc in crates_list {
34            let mut guard = crate_arc.lock().await;
35            // Show the crate using the ShowCrate trait, but skip merge_crates logic 
36            // since we want each crate separate in a workspace scenario.
37            // We'll do a local copy of `options` with merge_crates=false forced if needed,
38            // because "workspace" subcommand in the old code never merges them.
39            let mut local_opts = options.clone();
40            // The old CLI code never merges all crates in a workspace, so we forcibly disable it:
41            local_opts.set_merge_crates(false);
42
43            let cci_str = guard.show(&local_opts).await.map_err(WorkspaceError::CrateError)?;
44            let crate_name = guard.name();
45            let info_line = format!("// ---------------- [ Crate: {} ]\n", crate_name);
46            info!("{}", info_line.trim());
47
48            if cci_str.trim().is_empty() {
49                if *options.show_items_with_no_data() {
50                    output.push_str(&info_line);
51                    output.push_str("<no-data-for-crate>\n\n");
52                }
53            } else {
54                output.push_str(&info_line);
55                output.push_str(&cci_str);
56                output.push('\n');
57            }
58        }
59
60        if output.trim().is_empty() && *options.show_items_with_no_data() {
61            output = "<no-data>\n".to_string();
62        }
63
64        Ok(output)
65    }
66}