Skip to content

Commit 9e2b903

Browse files
jqnatividadclaude
andauthored
fix(qsvdp): only list commands actually compiled into the binary (#3816) (#3819)
qsvdp's COMMAND_LIST was a static string that unconditionally advertised joinp/luau/pivotp/sqlp even when the polars/luau features weren't compiled in, while the Command enum and dispatch already gated them. Replace it with a runtime-built `build_command_list()` (mirroring src/main.rs) that emits those entries — and the 🐻‍❄️/👑 legend lines — only when the corresponding feature is enabled. Used at both call sites (--list and the bare-qsvdp "Please choose one" message). Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent efd991b commit 9e2b903

1 file changed

Lines changed: 82 additions & 45 deletions

File tree

src/maindp.rs

Lines changed: 82 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,46 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
5454
#[global_allocator]
5555
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
5656

57-
static COMMAND_LIST: &str = r#"
58-
applydp Apply series of transformations to a column
57+
mod clitypes;
58+
mod cmd;
59+
mod config;
60+
mod index;
61+
mod lookup;
62+
mod odhtcache;
63+
mod select;
64+
mod util;
65+
66+
static USAGE: &str = r#"
67+
Usage:
68+
qsvdp <command> [<args>...]
69+
qsvdp [options]
70+
71+
Options:
72+
--list List all commands available.
73+
--envlist List all qsv-relevant environment variables.
74+
-u, --update Check for the latest qsv release.
75+
-U, --updatenow Update qsv to the latest release from GitHub without confirming.
76+
-h, --help Display this message
77+
<command> -h Display the command help message
78+
-v, --version Print version info, mem allocator, features installed,
79+
max_jobs, num_cpus, build info then exit"#;
80+
#[derive(Deserialize)]
81+
struct Args {
82+
arg_command: Option<Command>,
83+
flag_list: bool,
84+
flag_envlist: bool,
85+
flag_update: bool,
86+
flag_updatenow: bool,
87+
}
88+
89+
/// Build the "Installed commands:" listing dynamically so feature-gated commands
90+
/// (joinp/pivotp/sqlp under `polars`, luau under `luau`) only appear when
91+
/// actually compiled in. The `Command` enum and dispatch already gate these;
92+
/// the help text must match.
93+
fn build_command_list() -> String {
94+
let mut enabled_commands = String::from("\n");
95+
enabled_commands.push_str(
96+
" applydp Apply series of transformations to a column
5997
blake3 Compute BLAKE3 cryptographic hashes of files
6098
count Count records
6199
datefmt Format date/datetime strings
@@ -72,12 +110,22 @@ static COMMAND_LIST: &str = r#"
72110
help Show this usage message
73111
index Create CSV index for faster access
74112
input Read CSVs w/ special quoting, skipping, trimming & transcoding rules
75-
join Join CSV files
76-
joinp Join CSV files using the Pola.rs engine 🐻‍❄️
77-
luau Execute Luau script on CSV data 👑
78-
moarstats Add "moar" statistics to existing stats CSV
79-
pivotp Pivot CSV data 🐻‍❄️
80-
pragmastat Pragmatic statistical toolkit
113+
join Join CSV files\n",
114+
);
115+
116+
#[cfg(feature = "polars")]
117+
enabled_commands.push_str(" joinp Join CSV files using the Pola.rs engine 🐻‍❄️\n");
118+
119+
#[cfg(feature = "luau")]
120+
enabled_commands.push_str(" luau Execute Luau script on CSV data 👑\n");
121+
122+
enabled_commands.push_str(" moarstats Add \"moar\" statistics to existing stats CSV\n");
123+
124+
#[cfg(feature = "polars")]
125+
enabled_commands.push_str(" pivotp Pivot CSV data 🐻‍❄️\n");
126+
127+
enabled_commands.push_str(
128+
" pragmastat Pragmatic statistical toolkit
81129
pseudo Pseudonymise the values of a column
82130
rename Rename the columns of CSV data efficiently
83131
replace Replace patterns in CSV data
@@ -91,46 +139,30 @@ static COMMAND_LIST: &str = r#"
91139
snappy Compress/decompress data using the Snappy algorithm
92140
sniff Quickly sniff CSV metadata
93141
sort Sort CSV data in alphabetical, numerical, reverse or random order
94-
sortcheck Check if a CSV is sorted
95-
sqlp Run a SQL query against several CSVs using the Pola.rs engine 🐻‍❄️
96-
stats Infer data types and compute summary statistics
142+
sortcheck Check if a CSV is sorted\n",
143+
);
144+
145+
#[cfg(feature = "polars")]
146+
enabled_commands.push_str(
147+
" sqlp Run a SQL query against several CSVs using the Pola.rs engine 🐻‍❄️\n",
148+
);
149+
150+
enabled_commands.push_str(
151+
" stats Infer data types and compute summary statistics
97152
template Render templates using CSV data
98-
validate Validate CSV data for RFC4180-compliance or with JSON Schema
153+
validate Validate CSV data for RFC4180-compliance or with JSON Schema\n",
154+
);
99155

100-
NOTE: qsvdp ignores the --progressbar option for all commands.
101-
🐻‍❄️ - requires polars feature
102-
👑 - requires luau feature"#;
156+
enabled_commands
157+
.push_str("\n NOTE: qsvdp ignores the --progressbar option for all commands.");
103158

104-
mod clitypes;
105-
mod cmd;
106-
mod config;
107-
mod index;
108-
mod lookup;
109-
mod odhtcache;
110-
mod select;
111-
mod util;
159+
#[cfg(feature = "polars")]
160+
enabled_commands.push_str("\n 🐻‍❄️ - requires polars feature");
112161

113-
static USAGE: &str = r#"
114-
Usage:
115-
qsvdp <command> [<args>...]
116-
qsvdp [options]
162+
#[cfg(feature = "luau")]
163+
enabled_commands.push_str("\n 👑 - requires luau feature");
117164

118-
Options:
119-
--list List all commands available.
120-
--envlist List all qsv-relevant environment variables.
121-
-u, --update Check for the latest qsv release.
122-
-U, --updatenow Update qsv to the latest release from GitHub without confirming.
123-
-h, --help Display this message
124-
<command> -h Display the command help message
125-
-v, --version Print version info, mem allocator, features installed,
126-
max_jobs, num_cpus, build info then exit"#;
127-
#[derive(Deserialize)]
128-
struct Args {
129-
arg_command: Option<Command>,
130-
flag_list: bool,
131-
flag_envlist: bool,
132-
flag_update: bool,
133-
flag_updatenow: bool,
165+
enabled_commands
134166
}
135167

136168
fn main() -> QsvExitCode {
@@ -160,7 +192,11 @@ fn main() -> QsvExitCode {
160192
}
161193

162194
if args.flag_list {
163-
wout!("Installed commands:{}\n\n{}", COMMAND_LIST, SPONSOR_MESSAGE);
195+
wout!(
196+
"Installed commands:{}\n\n{}",
197+
build_command_list(),
198+
SPONSOR_MESSAGE
199+
);
164200
util::log_end(qsv_args, now);
165201
return QsvExitCode::Good;
166202
} else if args.flag_envlist {
@@ -178,10 +214,11 @@ fn main() -> QsvExitCode {
178214
}
179215
match args.arg_command {
180216
None => {
217+
let command_list = build_command_list();
181218
werr!(
182219
"qsvdp is a suite of CSV command line utilities optimized for \
183220
Datapusher+.\n\nPlease choose one of the following \
184-
commands:\n{COMMAND_LIST}\n\n{SPONSOR_MESSAGE}",
221+
commands:\n{command_list}\n\n{SPONSOR_MESSAGE}",
185222
);
186223

187224
util::log_end(qsv_args, now);

0 commit comments

Comments
 (0)