1use std::path::Path;
7use std::path::PathBuf;
8
9use vortex::array::stream::ArrayStreamExt;
10use vortex::error::VortexResult;
11use vortex::file::OpenOptionsSessionExt;
12use vortex::session::VortexSession;
13
14#[derive(Debug, clap::Parser)]
16pub struct TreeArgs {
17 #[clap(subcommand)]
19 pub mode: TreeMode,
20}
21
22#[derive(Debug, clap::Subcommand)]
24pub enum TreeMode {
25 Array {
27 file: PathBuf,
29 },
30 Layout {
32 file: PathBuf,
34 #[arg(short, long)]
36 verbose: bool,
37 },
38}
39
40pub async fn exec_tree(session: &VortexSession, args: TreeArgs) -> VortexResult<()> {
46 match args.mode {
47 TreeMode::Array { file } => exec_array_tree(session, &file).await?,
48 TreeMode::Layout { file, verbose } => exec_layout_tree(session, &file, verbose).await?,
49 }
50
51 Ok(())
52}
53
54async fn exec_array_tree(session: &VortexSession, file: &Path) -> VortexResult<()> {
55 let full = session
56 .open_options()
57 .open(file)
58 .await?
59 .scan()?
60 .into_array_stream()?
61 .read_all()
62 .await?;
63
64 println!("{}", full.display_tree());
65
66 Ok(())
67}
68
69async fn exec_layout_tree(session: &VortexSession, file: &Path, verbose: bool) -> VortexResult<()> {
70 let vxf = session.open_options().open(file).await?;
71
72 if verbose {
73 let output = vxf
75 .footer()
76 .layout()
77 .display_tree_with_segments(vxf.segment_source())
78 .await?;
79 println!("{}", output);
80 } else {
81 println!("{}", vxf.footer().layout().display_tree());
83 }
84
85 Ok(())
86}