crate::ix!();
#[derive(Debug, StructOpt, Getters, Setters, Builder)]
#[getset(get = "pub")]
#[builder(setter(into))]
pub struct TreeSubcommand {
#[structopt(long, default_value = "999")]
levels: usize,
#[structopt(long)]
show_version: bool,
#[structopt(long)]
show_path: bool,
#[structopt(long)]
verbose: bool,
#[structopt(long)]
crate_name: Option<String>,
}
impl TreeSubcommand {
pub async fn run(&self) -> Result<(), WorkspaceError> {
use tracing::{debug, error, info, trace};
trace!(
"Entering TreeSubcommand::run (levels={}, show_version={}, show_path={}, verbose={}, crate_name={:?})",
self.levels(),
self.show_version(),
self.show_path(),
self.verbose(),
self.crate_name(),
);
let path = match std::env::current_dir() {
Ok(p) => {
debug!("Current dir = {:?}", p);
p
}
Err(e) => {
error!("Failed to get current dir: {:?}", e);
return Err(WorkspaceError::IoError {
io_error: Arc::new(e),
context: "Could not obtain current working directory".to_string(),
});
}
};
let ws = match Workspace::<PathBuf, CrateHandle>::new(&path).await {
Ok(w) => {
info!("Successfully built workspace at path: {:?}", path);
w
}
Err(e) => {
error!("Error building workspace: {:?}", e);
return Err(e);
}
};
let tree = if let Some(name) = self.crate_name() {
info!("Building subtree for specified crate: {}", name);
ws.build_workspace_subtree(name, *self.levels(), *self.verbose())
.await?
} else {
debug!("No specific crate requested => building full workspace tree");
ws.build_workspace_tree(*self.levels(), *self.verbose()).await?
};
let output_str = tree.render(*self.show_version(), *self.show_path());
println!("{}", output_str);
Ok(())
}
}