workspacer_cli/
show.rs

1// ---------------- [ File: workspacer-cli/src/show.rs ]
2crate::ix!();
3
4#[derive(Debug, StructOpt)]
5pub enum ShowSubcommand {
6    /// Show info for a single crate only
7    #[structopt(name = "crate")]
8    Crate(ShowFlags),
9
10    /// Show info for a single crate plus its internal deps,
11    /// concatenating all consolidated interfaces into one final result
12    #[structopt(name = "crate-tree")]
13    CrateTree(ShowFlags),
14
15    /// Show info for the entire workspace
16    #[structopt(name = "workspace")]
17    Workspace(ShowFlags),
18}
19
20impl ShowSubcommand {
21    /// Runs the show subcommand. We dispatch to one of the subroutines below, which replicate
22    /// the old CLI logic: 
23    /// - "crate" => single crate only 
24    /// - "crate-tree" => single crate plus all its internal deps, either merged or separate 
25    /// - "workspace" => entire workspace
26    #[tracing::instrument(level = "trace", skip(self))]
27    pub async fn run(&self) -> Result<(), WorkspaceError> {
28        trace!("Entering ShowSubcommand::run");
29        let mut final_output = String::new();
30
31        match self {
32            ShowSubcommand::Crate(flags) => {
33                let out = show_crate(flags).await?;
34                final_output.push_str(&out);
35            }
36            ShowSubcommand::CrateTree(flags) => {
37                let out = show_crate_tree(flags).await?;
38                final_output.push_str(&out);
39            }
40            ShowSubcommand::Workspace(flags) => {
41                let out = show_workspace(flags).await?;
42                final_output.push_str(&out);
43            }
44        }
45
46        if final_output.trim().is_empty() {
47            trace!("No data produced in ShowSubcommand::run");
48        } else {
49            println!("{}", final_output);
50        }
51
52        Ok(())
53    }
54}