1mod cat;
2mod common;
3mod head;
4mod lance;
5mod rowcount;
6mod sample;
7mod schema;
8mod tail;
9mod take;
10
11use crate::Result;
12use crate::cli::{Cli, Command, Format};
13use crate::error::Error;
14
15pub async fn dispatch(cli: Cli) -> Result<()> {
16 let columns = cli.columns.as_deref();
17 let exclude = cli.exclude_columns.as_deref();
18 let binary_format = cli.binary_format;
19 if let Some(name) = command_ignoring_format(&cli.command)
20 && cli.format.is_some()
21 {
22 return Err(Error::FormatNotApplicable { command: name });
23 }
24 let format = resolve_format(cli.format, &cli.command);
25 match cli.command {
26 Command::Cat { inputs, lance } => {
27 cat::run(&inputs, format, binary_format, columns, exclude, &lance).await
28 }
29 Command::Head {
30 input,
31 limit,
32 lance,
33 } => {
34 head::run(
35 &input,
36 limit,
37 format,
38 binary_format,
39 columns,
40 exclude,
41 &lance,
42 )
43 .await
44 }
45 Command::Tail {
46 input,
47 limit,
48 lance,
49 } => {
50 tail::run(
51 &input,
52 limit,
53 format,
54 binary_format,
55 columns,
56 exclude,
57 &lance,
58 )
59 .await
60 }
61 Command::Take {
62 input,
63 indices,
64 lance,
65 } => {
66 take::run(
67 &input,
68 &indices,
69 format,
70 binary_format,
71 columns,
72 exclude,
73 &lance,
74 )
75 .await
76 }
77 Command::Rowcount { input, lance } => rowcount::run(&input, &lance).await,
78 Command::Sample {
79 input,
80 limit,
81 seed,
82 lance,
83 } => {
84 sample::run(
85 &input,
86 limit,
87 seed,
88 format,
89 binary_format,
90 columns,
91 exclude,
92 &lance,
93 )
94 .await
95 }
96 Command::Schema { input, ty, lance } => {
97 schema::run(&input, ty, columns, exclude, &lance).await
98 }
99 Command::Versions {
100 input,
101 branch,
102 tagged_only,
103 } => {
104 lance::versions::run(
105 &input,
106 branch.as_deref(),
107 tagged_only,
108 format,
109 binary_format,
110 )
111 .await
112 }
113 Command::Branches { input } => lance::branches::run(&input, format, binary_format).await,
114 Command::Tags { input } => lance::tags::run(&input, format, binary_format).await,
115 Command::Indices {
116 input,
117 lance: lance_args,
118 } => lance::indices::run(&input, &lance_args, format, binary_format).await,
119 }
120}
121
122fn resolve_format(explicit: Option<Format>, cmd: &Command) -> Format {
126 if let Some(f) = explicit {
127 return f;
128 }
129 match cmd {
130 Command::Versions { .. }
131 | Command::Branches { .. }
132 | Command::Tags { .. }
133 | Command::Indices { .. } => Format::Table,
134 _ => Format::Jsonl,
135 }
136}
137
138fn command_ignoring_format(cmd: &Command) -> Option<&'static str> {
141 match cmd {
142 Command::Rowcount { .. } => Some("rowcount"),
143 Command::Schema { .. } => Some("schema"),
144 _ => None,
145 }
146}