Skip to content

Commit 40497c6

Browse files
prontclaude
andauthored
fix(cli): decouple cli feature from stdlib (#1709)
The cli feature previously depended on stdlib (which includes all enable_* functions: env, network, system, crypto). This forced every downstream user that enabled cli to pull in all stdlib functions, with no way to opt out. The cli code already accepted stdlib functions as an injected parameter (Vec<Box<dyn Function>>), but also had four hardcoded crate::stdlib::all() calls that created the implicit stdlib dependency. This replaces those calls to use the injected functions instead. The vrl binary now explicitly requires both cli and stdlib features. Callers (e.g. Vector) can pair cli with stdlib-base or any subset of enable_* features they choose. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent aae1393 commit 40497c6

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ datadog_grok = ["value", "parsing", "dep:nom", "dep:peeking_take_while", "dep:se
6363
datadog_search = ["dep:pest", "dep:pest_derive", "dep:itertools", "dep:regex", "dep:serde"]
6464

6565
# Contains functionality to create a CLI for VRL.
66-
cli = ["stdlib", "dep:clap", "dep:serde_json", "dep:thiserror", "dep:exitcode", "dep:webbrowser", "dep:rustyline", "dep:prettytable-rs"]
66+
cli = ["compiler", "dep:clap", "dep:serde_json", "dep:thiserror", "dep:exitcode", "dep:webbrowser", "dep:rustyline", "dep:prettytable-rs"]
6767

6868
# Contains the test framework for testing VRL functions. Useful for testing custom functions.
6969
test_framework = ["compiler", "dep:prettydiff", "dep:serde_json", "dep:nu-ansi-term"]
@@ -329,7 +329,7 @@ ua-parser = { version = "0.2" }
329329
[[bin]]
330330
name = "vrl"
331331
path = "src/main.rs"
332-
required-features = ["cli"]
332+
required-features = ["cli", "stdlib"]
333333

334334
[[bench]]
335335
name = "kind"

src/cli/cmd.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,10 @@ fn run(opts: &Opts, stdlib_functions: Vec<Box<dyn Function>>) -> Result<(), Erro
142142
program,
143143
warnings,
144144
config: _,
145-
} = compile_with_state(
146-
&source,
147-
&crate::stdlib::all(),
148-
&state,
149-
CompileConfig::default(),
150-
)
151-
.map_err(|diagnostics| {
152-
Error::Parse(Formatter::new(&source, diagnostics).colored().to_string())
153-
})?;
145+
} = compile_with_state(&source, &stdlib_functions, &state, CompileConfig::default())
146+
.map_err(|diagnostics| {
147+
Error::Parse(Formatter::new(&source, diagnostics).colored().to_string())
148+
})?;
154149

155150
#[allow(clippy::print_stderr)]
156151
if opts.print_warnings {

src/cli/repl.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ pub(crate) fn run(
7979
Ok(line) if line == "exit" || line == "quit" => break,
8080
Ok("help") => print_help_text(),
8181
Ok(line) if line == "help functions" || line == "help funcs" || line == "help fs" => {
82-
print_function_list();
82+
print_function_list(&stdlib_functions);
8383
}
8484
Ok("help docs") => open_url(DOCS_URL),
8585
// Capture "help error <code>"
8686
Ok(line) if error_docs_regex.is_match(line) => show_error_docs(line, &error_docs_regex),
8787
// Capture "help docs <func_name>"
88-
Ok(line) if func_docs_regex.is_match(line) => show_func_docs(line, &func_docs_regex),
88+
Ok(line) if func_docs_regex.is_match(line) => {
89+
show_func_docs(line, &func_docs_regex, &stdlib_functions);
90+
}
8991
Ok(line) => {
9092
rl.add_history_entry(line)?;
9193

@@ -239,7 +241,8 @@ impl Hinter for Repl {
239241
let mut hints: Vec<String> = Vec::new();
240242

241243
// Add all function names to the hints
242-
let mut func_names = crate::stdlib::all()
244+
let mut func_names = self
245+
.stdlib_functions
243246
.iter()
244247
.map(|f| f.identifier().into())
245248
.collect::<Vec<String>>();
@@ -334,13 +337,13 @@ impl Validator for Repl {
334337
}
335338
}
336339

337-
fn print_function_list() {
340+
fn print_function_list(funcs: &[Box<dyn Function>]) {
338341
let table_format = *format::consts::FORMAT_NO_LINESEP_WITH_TITLE;
339342
let num_columns = 3;
340343

341344
let mut func_table = Table::new();
342345
func_table.set_format(table_format);
343-
crate::stdlib::all()
346+
funcs
344347
.chunks(num_columns)
345348
.map(|funcs| {
346349
// Because it's possible that some chunks are only partial, e.g. have only two Some(_)
@@ -380,16 +383,13 @@ fn open_url(url: &str) {
380383
}
381384
}
382385

383-
fn show_func_docs(line: &str, pattern: &Regex) {
386+
fn show_func_docs(line: &str, pattern: &Regex, funcs: &[Box<dyn Function>]) {
384387
// Unwrap is okay in both cases here, as there's guaranteed to be two matches ("help docs" and
385388
// "help docs <func_name>")
386389
let matches = pattern.captures(line).unwrap();
387390
let func_name = matches.get(1).unwrap().as_str();
388391

389-
if crate::stdlib::all()
390-
.iter()
391-
.any(|f| f.identifier() == func_name)
392-
{
392+
if funcs.iter().any(|f| f.identifier() == func_name) {
393393
let func_url = format!("{DOCS_URL}/functions/#{func_name}");
394394
open_url(&func_url);
395395
} else {

0 commit comments

Comments
 (0)