1#![deny(clippy::missing_errors_doc)]
25#![deny(clippy::missing_panics_doc)]
26#![deny(clippy::missing_safety_doc)]
27#![deny(missing_docs)]
28
29#[cfg_attr(
30 all(not(feature = "native"), not(target_arch = "wasm32")),
31 allow(dead_code, unused_imports)
32)]
33pub mod browse;
34pub mod segment_tree;
35
36#[cfg(feature = "native")]
37pub mod convert;
38#[cfg(feature = "native")]
39pub mod datafusion_helper;
40#[cfg(feature = "native")]
41pub mod inspect;
42#[cfg(feature = "native")]
43pub mod query;
44#[cfg(feature = "native")]
45pub mod segments;
46#[cfg(feature = "native")]
47pub mod tree;
48
49#[cfg(target_arch = "wasm32")]
50pub mod wasm;
51
52#[cfg(feature = "native")]
53mod native_cli {
54 use std::ffi::OsString;
55 use std::path::PathBuf;
56
57 use clap::CommandFactory;
58 use clap::Parser;
59 use vortex::error::VortexExpect;
60 use vortex::session::VortexSession;
61
62 #[derive(clap::Parser)]
63 #[command(version)]
64 struct Cli {
65 #[clap(subcommand)]
66 command: Commands,
67 }
68
69 #[derive(Debug, clap::Subcommand)]
70 enum Commands {
71 Tree(super::tree::TreeArgs),
73 Convert(#[command(flatten)] super::convert::ConvertArgs),
75 Browse { file: PathBuf },
77 Inspect(super::inspect::InspectArgs),
79 Query(super::query::QueryArgs),
81 Segments(super::segments::SegmentsArgs),
83 }
84
85 impl Commands {
86 fn file_path(&self) -> &PathBuf {
87 match self {
88 Commands::Tree(args) => match &args.mode {
89 super::tree::TreeMode::Array { file, .. } => file,
90 super::tree::TreeMode::Layout { file, .. } => file,
91 },
92 Commands::Browse { file } => file,
93 Commands::Convert(flags) => &flags.file,
94 Commands::Inspect(args) => &args.file,
95 Commands::Query(args) => &args.file,
96 Commands::Segments(args) => &args.file,
97 }
98 }
99 }
100
101 pub async fn launch(session: &VortexSession) -> anyhow::Result<()> {
109 launch_from(session, std::env::args_os()).await
110 }
111
112 pub async fn launch_from(
121 session: &VortexSession,
122 args: impl IntoIterator<Item = impl Into<OsString> + Clone>,
123 ) -> anyhow::Result<()> {
124 let _ = env_logger::try_init();
125
126 let cli = Cli::parse_from(args);
127
128 let path = cli.command.file_path();
129 if !std::fs::exists(path)? {
130 Cli::command()
131 .error(
132 clap::error::ErrorKind::Io,
133 format!(
134 "File '{}' does not exist.",
135 path.to_str().vortex_expect("file path")
136 ),
137 )
138 .exit()
139 }
140
141 match cli.command {
142 Commands::Tree(args) => super::tree::exec_tree(session, args).await?,
143 Commands::Convert(flags) => super::convert::exec_convert(session, flags).await?,
144 Commands::Browse { file } => super::browse::exec_tui(session, file).await?,
145 Commands::Inspect(args) => super::inspect::exec_inspect(session, args).await?,
146 Commands::Query(args) => super::query::exec_query(session, args).await?,
147 Commands::Segments(args) => super::segments::exec_segments(session, args).await?,
148 };
149
150 Ok(())
151 }
152}
153
154#[cfg(feature = "native")]
155pub use native_cli::launch;
156#[cfg(feature = "native")]
157pub use native_cli::launch_from;