1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
use crate::config::config_file::trust_check;
use crate::dirs;
use crate::env;
use crate::env_diff::EnvMap;
use crate::file::display_path;
use crate::path_env::PathEnv;
use crate::tera::{get_tera, tera_exec};
use eyre::{Context, eyre};
use indexmap::IndexMap;
use itertools::Itertools;
use serde_json::Value;
use std::borrow::Cow;
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::fmt::{Debug, Display, Formatter};
use std::path::{Path, PathBuf};
use std::{cmp::PartialEq, sync::Arc};
use super::{Config, Settings};
mod file;
mod module;
mod path;
mod source;
pub(crate) mod venv;
#[derive(Debug, Clone, Default, PartialEq)]
pub enum RequiredValue {
#[default]
False,
True,
Help(String),
}
impl RequiredValue {
pub fn is_required(&self) -> bool {
!matches!(self, RequiredValue::False)
}
pub fn help_text(&self) -> Option<&str> {
match self {
RequiredValue::Help(text) => Some(text.as_str()),
_ => None,
}
}
}
impl<'de> serde::Deserialize<'de> for RequiredValue {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
use serde::de::{self, Visitor};
use std::fmt;
struct RequiredVisitor;
impl<'de> Visitor<'de> for RequiredVisitor {
type Value = RequiredValue;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a boolean or a string")
}
fn visit_bool<E>(self, value: bool) -> Result<RequiredValue, E>
where
E: de::Error,
{
Ok(if value {
RequiredValue::True
} else {
RequiredValue::False
})
}
fn visit_str<E>(self, value: &str) -> Result<RequiredValue, E>
where
E: de::Error,
{
Ok(RequiredValue::Help(value.to_string()))
}
fn visit_string<E>(self, value: String) -> Result<RequiredValue, E>
where
E: de::Error,
{
Ok(RequiredValue::Help(value))
}
}
deserializer.deserialize_any(RequiredVisitor)
}
}
impl serde::Serialize for RequiredValue {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match self {
RequiredValue::False => serializer.serialize_bool(false),
RequiredValue::True => serializer.serialize_bool(true),
RequiredValue::Help(text) => serializer.serialize_str(text),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct EnvDirectiveOptions {
#[serde(default)]
pub(crate) tools: bool,
#[serde(default)]
pub(crate) redact: Option<bool>,
#[serde(default)]
pub(crate) required: RequiredValue,
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum EnvDirective {
/// simple key/value pair
Val(String, String, EnvDirectiveOptions),
/// remove a key
Rm(String, EnvDirectiveOptions),
/// Required variable that must be defined elsewhere
Required(String, EnvDirectiveOptions),
/// dotenv file
File(String, EnvDirectiveOptions),
/// add a path to the PATH
Path(String, EnvDirectiveOptions),
/// run a bash script and apply the resulting env diff
Source(String, EnvDirectiveOptions),
/// [experimental] age-encrypted value
Age {
key: String,
value: String,
format: Option<AgeFormat>,
options: EnvDirectiveOptions,
},
PythonVenv {
path: String,
create: bool,
python: Option<String>,
uv_create_args: Option<Vec<String>>,
python_create_args: Option<Vec<String>>,
options: EnvDirectiveOptions,
},
Module(String, toml::Value, EnvDirectiveOptions),
}
impl EnvDirective {
pub fn options(&self) -> &EnvDirectiveOptions {
match self {
EnvDirective::Val(_, _, opts)
| EnvDirective::Rm(_, opts)
| EnvDirective::Required(_, opts)
| EnvDirective::File(_, opts)
| EnvDirective::Path(_, opts)
| EnvDirective::Source(_, opts)
| EnvDirective::Age { options: opts, .. }
| EnvDirective::PythonVenv { options: opts, .. }
| EnvDirective::Module(_, _, opts) => opts,
}
}
}
impl From<(String, String)> for EnvDirective {
fn from((k, v): (String, String)) -> Self {
Self::Val(k, v, Default::default())
}
}
impl From<(String, i64)> for EnvDirective {
fn from((k, v): (String, i64)) -> Self {
(k, v.to_string()).into()
}
}
impl Display for EnvDirective {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EnvDirective::Val(k, v, _) => write!(f, "{k}={v}"),
EnvDirective::Rm(k, _) => write!(f, "unset {k}"),
EnvDirective::Required(k, _) => write!(f, "{k} (required)"),
EnvDirective::File(path, _) => write!(f, "_.file = \"{}\"", display_path(path)),
EnvDirective::Path(path, _) => write!(f, "_.path = \"{}\"", display_path(path)),
EnvDirective::Source(path, _) => write!(f, "_.source = \"{}\"", display_path(path)),
EnvDirective::Age { key, format, .. } => {
write!(f, "{key} (age-encrypted")?;
if let Some(fmt) = format {
let fmt_str = match fmt {
AgeFormat::Zstd => "zstd",
AgeFormat::Raw => "raw",
};
write!(f, ", {fmt_str}")?;
}
write!(f, ")")
}
EnvDirective::Module(name, _, _) => write!(f, "module {name}"),
EnvDirective::PythonVenv {
path,
create,
python,
uv_create_args,
python_create_args,
..
} => {
write!(f, "python venv path={}", display_path(path))?;
if *create {
write!(f, " create")?;
}
if let Some(python) = python {
write!(f, " python={python}")?;
}
if let Some(args) = uv_create_args {
write!(f, " uv_create_args={args:?}")?;
}
if let Some(args) = python_create_args {
write!(f, " python_create_args={args:?}")?;
}
Ok(())
}
}
}
}
#[derive(Debug, Clone, PartialEq, Default, serde::Serialize, serde::Deserialize)]
pub enum AgeFormat {
#[serde(rename = "zstd")]
Zstd,
#[serde(rename = "raw")]
#[default]
Raw,
}
#[derive(Default, Clone)]
pub struct EnvResults {
pub env: IndexMap<String, (String, PathBuf)>,
pub vars: IndexMap<String, (String, PathBuf)>,
pub env_remove: BTreeSet<String>,
pub env_files: Vec<PathBuf>,
pub env_paths: Vec<PathBuf>,
pub env_scripts: Vec<PathBuf>,
pub redactions: Vec<String>,
pub tool_add_paths: Vec<PathBuf>,
/// Files to watch for cache invalidation (from modules and _.source directives)
pub watch_files: Vec<PathBuf>,
/// True if any directive declared cacheable=false or is a dynamic module
pub has_uncacheable: bool,
}
#[derive(Debug, Clone, Default)]
pub enum ToolsFilter {
ToolsOnly,
#[default]
NonToolsOnly,
Both,
}
pub struct EnvResolveOptions {
pub vars: bool,
pub tools: ToolsFilter,
pub warn_on_missing_required: bool,
}
impl EnvResults {
pub async fn resolve(
config: &Arc<Config>,
mut ctx: tera::Context,
initial: &EnvMap,
input: Vec<(EnvDirective, PathBuf)>,
resolve_opts: EnvResolveOptions,
) -> eyre::Result<Self> {
// trace!("resolve: input: {:#?}", &input);
let mut env = initial
.iter()
.map(|(k, v)| (k.clone(), (v.clone(), None)))
.collect::<IndexMap<_, _>>();
let mut r = Self::default();
let normalize_path = |config_root: &Path, p: PathBuf| {
let p = p.strip_prefix("./").unwrap_or(&p);
match p.strip_prefix("~/") {
Ok(p) => dirs::HOME.join(p),
_ if p.is_relative() => config_root.join(p),
_ => p.to_path_buf(),
}
};
let mut paths: Vec<(PathBuf, PathBuf)> = Vec::new();
let last_python_venv = input.iter().rev().find_map(|(d, _)| match d {
EnvDirective::PythonVenv { .. } => Some(d),
_ => None,
});
let filtered_input = input
.iter()
.fold(Vec::new(), |mut acc, (directive, source)| {
// Filter directives based on tools setting
let should_include = match &resolve_opts.tools {
ToolsFilter::ToolsOnly => directive.options().tools,
ToolsFilter::NonToolsOnly => !directive.options().tools,
ToolsFilter::Both => true,
};
if !should_include {
return acc;
}
if let Some(d) = &last_python_venv
&& matches!(directive, EnvDirective::PythonVenv { .. })
&& **d != *directive
{
// skip venv directives if it's not the last one
return acc;
}
acc.push((directive.clone(), source.clone()));
acc
});
// Save filtered_input for validation after processing
let filtered_input_for_validation = filtered_input.clone();
for (directive, source) in filtered_input {
let mut tera = get_tera(source.parent());
tera.register_function(
"exec",
tera_exec(
source.parent().map(|d| d.to_path_buf()),
env.iter()
.map(|(k, (v, _))| (k.clone(), v.clone()))
.collect(),
),
);
// trace!(
// "resolve: directive: {:?}, source: {:?}",
// &directive,
// &source
// );
let config_root = crate::config::config_file::config_root::config_root(&source);
ctx.insert("cwd", &*dirs::CWD);
ctx.insert("config_root", &config_root);
let env_vars = env
.iter()
.map(|(k, (v, _))| (k.clone(), v.clone()))
.collect::<EnvMap>();
ctx.insert("env", &env_vars);
let mut vars: EnvMap = if let Some(Value::Object(existing_vars)) = ctx.get("vars") {
existing_vars
.iter()
.filter_map(|(k, v)| v.as_str().map(|s| (k.clone(), s.to_string())))
.collect()
} else {
EnvMap::new()
};
vars.extend(r.vars.iter().map(|(k, (v, _))| (k.clone(), v.clone())));
ctx.insert("vars", &vars);
let redact = directive.options().redact;
// trace!("resolve: ctx.get('env'): {:#?}", &ctx.get("env"));
match directive {
EnvDirective::Val(k, v, _opts) => {
let v = r.parse_template(&ctx, &mut tera, &source, &v)?;
if resolve_opts.vars {
r.vars.insert(k, (v, source.clone()));
} else {
r.env_remove.remove(&k);
// trace!("resolve: inserting {:?}={:?} from {:?}", &k, &v, &source);
if redact.unwrap_or(false) {
r.redactions.push(k.clone());
}
env.insert(k, (v, Some(source.clone())));
}
}
EnvDirective::Rm(k, _opts) => {
env.shift_remove(&k);
r.env_remove.insert(k);
}
EnvDirective::Required(_k, _opts) => {
// Required directives don't set any value - they only validate during validation phase
// The actual value must come from the initial environment or a later config file
}
EnvDirective::Age {
key: ref k,
ref options,
..
} => {
// Decrypt age-encrypted value
let res = crate::agecrypt::decrypt_age_directive(&directive).await;
let decrypted_v = match res {
Ok(decrypted_v) => {
// Parse as template after decryption
r.parse_template(&ctx, &mut tera, &source, &decrypted_v)?
}
Err(e) if Settings::get().age.strict => {
return Err(e)
.wrap_err(eyre!("[experimental] Failed to decrypt {}", k));
}
Err(e) => {
debug!(
"[experimental] Age decryption failed for {} but continuing in non-strict mode: {}",
k, e
);
// continue to the next directive
continue;
}
};
if resolve_opts.vars {
r.vars.insert(k.clone(), (decrypted_v, source.clone()));
} else {
r.env_remove.remove(k);
// Handle redaction for age-encrypted values
// We're already in the EnvDirective::Age match arm, so we know this is an Age directive
// For age-encrypted values, we default to redacting for security
// With nullable redact, we can now distinguish between:
// - None: not specified (default for age is to redact for security)
// - Some(true): explicitly redact
// - Some(false): explicitly don't redact
debug!("Age directive {}: redact = {:?}", k, options.redact);
match options.redact {
Some(false) => {
// User explicitly set redact = false - don't redact
debug!(
"Age directive {}: NOT redacting (explicit redact = false)",
k
);
}
Some(true) | None => {
// Either explicitly redact or use age default (redact for security)
debug!(
"Age directive {}: redacting (redact = {:?})",
k, options.redact
);
r.redactions.push(k.clone());
}
}
env.insert(k.clone(), (decrypted_v, Some(source.clone())));
}
}
EnvDirective::Path(input_str, _opts) => {
let path = Self::path(&mut ctx, &mut tera, &mut r, &source, input_str).await?;
paths.push((path.clone(), source.clone()));
// Don't modify PATH in env - just add to env_paths
// This allows consumers to control PATH ordering
}
EnvDirective::File(input, _opts) => {
let files = Self::file(
config,
&mut ctx,
&mut tera,
&mut r,
normalize_path,
&source,
&config_root,
input,
)
.await?;
for (f, new_env) in files {
r.env_files.push(f.clone());
for (k, v) in new_env {
if resolve_opts.vars {
r.vars.insert(k, (v, f.clone()));
} else {
if redact.unwrap_or(false) {
r.redactions.push(k.clone());
}
env.insert(k, (v, Some(f.clone())));
}
}
}
}
EnvDirective::Source(input, _opts) => {
let files = Self::source(
&mut ctx,
&mut tera,
&mut paths,
&mut r,
normalize_path,
&source,
&config_root,
&env_vars,
input,
)?;
for (f, new_env) in files {
r.env_scripts.push(f.clone());
for (k, v) in new_env {
if resolve_opts.vars {
r.vars.insert(k, (v, f.clone()));
} else {
if redact.unwrap_or(false) {
r.redactions.push(k.clone());
}
env.insert(k, (v, Some(f.clone())));
}
}
}
}
EnvDirective::PythonVenv {
path,
create,
python,
uv_create_args,
python_create_args,
options: _opts,
} => {
Self::venv(
config,
&mut ctx,
&mut tera,
&mut env,
&mut r,
normalize_path,
&source,
&config_root,
env_vars,
path,
create,
python,
uv_create_args,
python_create_args,
)
.await?;
}
EnvDirective::Module(name, value, _opts) => {
let mut env_map: IndexMap<String, String> = env
.iter()
.map(|(k, (v, _))| (k.clone(), v.clone()))
.collect();
// Incorporate _.path entries accumulated so far into PATH
// so that cmd.exec in the plugin can find tools on PATH.
if !paths.is_empty() {
let existing_path =
env_map.get(&*env::PATH_KEY).cloned().unwrap_or_default();
let mut path_env = PathEnv::from_path_str(&existing_path);
for (p, path_source) in &paths {
let config_root =
crate::config::config_file::config_root::config_root(path_source);
for s in env::split_paths(p) {
path_env.add(normalize_path(&config_root, s));
}
}
env_map.insert(env::PATH_KEY.to_string(), path_env.to_string());
}
if log::log_enabled!(log::Level::Trace) {
if let Some(path) = env_map.get(&*env::PATH_KEY) {
trace!("module {name}: PATH={path}");
} else {
trace!("module {name}: no PATH in env_map");
}
}
let env_before: IndexMap<String, (String, PathBuf)> = r.env.clone();
Self::module(&mut r, config, source, name, &value, redact, env_map).await?;
// Merge entries that this module call added or changed into
// the local `env` so they are visible in the Tera context
// for subsequent directives. Keys unchanged in `r.env`
// (same value before and after this call) are skipped, which
// preserves any Val/File/Source override in `env` applied
// after a prior module emitted the same value. When a
// module emits a *different* value the merge writes it
// through — "later directive wins", consistent with all
// other directive pairs.
for (k, (v, src)) in &r.env {
let added_or_changed = match env_before.get(k) {
Some((old_v, _)) => old_v != v,
None => true,
};
if added_or_changed {
env.insert(k.clone(), (v.clone(), Some(src.clone())));
}
}
}
};
}
let env_vars = env
.iter()
.map(|(k, (v, _))| (k.clone(), v.clone()))
.collect::<HashMap<_, _>>();
ctx.insert("env", &env_vars);
for (k, (v, source)) in env {
if let Some(source) = source {
r.env.insert(k, (v, source));
}
}
// trace!("resolve: paths: {:#?}", &paths);
// trace!("resolve: ctx.env: {:#?}", &ctx.get("env"));
for (source, paths) in &paths.iter().chunk_by(|(_, source)| source) {
// Use the computed config_root (project root for nested configs) for path resolution
// to be consistent with other env directives like _.source and _.file
let config_root = crate::config::config_file::config_root::config_root(source);
let paths = paths.map(|(p, _)| p).collect_vec();
let mut paths = paths
.iter()
.rev()
.flat_map(|path| env::split_paths(path))
.map(|s| normalize_path(&config_root, s))
.collect::<Vec<_>>();
// r.env_paths is already reversed and paths should prepend r.env_paths
paths.reverse();
paths.extend(r.env_paths);
r.env_paths = paths;
}
// Validate required environment variables
Self::validate_required_env_vars(
&filtered_input_for_validation,
initial,
&r,
resolve_opts.warn_on_missing_required,
)?;
Ok(r)
}
fn validate_required_env_vars(
input: &[(EnvDirective, PathBuf)],
initial: &EnvMap,
env_results: &EnvResults,
warn_mode: bool,
) -> eyre::Result<()> {
let mut required_vars = Vec::new();
// Collect all required environment variables with their options
for (directive, source) in input {
match directive {
EnvDirective::Val(key, _, options) if options.required.is_required() => {
required_vars.push((key.clone(), source.clone(), options.required.clone()));
}
EnvDirective::Required(key, options) => {
required_vars.push((key.clone(), source.clone(), options.required.clone()));
}
_ => {}
}
}
// Check if required variables are defined
for (var_name, declaring_source, required_value) in required_vars {
// Variable must be defined either:
// 1. In the initial environment (before mise runs), OR
// 2. In a config file processed later than the one declaring it as required
let is_predefined = initial.contains_key(&var_name);
let is_defined_later = if let Some((_, var_source)) = env_results.env.get(&var_name) {
// Check if the variable comes from a different config file
var_source != &declaring_source
} else {
false
};
if !is_predefined && !is_defined_later {
let base_message = format!(
"Required environment variable '{}' is not defined. It must be set before mise runs or in a later config file. (Required in: {})",
var_name,
display_path(declaring_source)
);
let message = if let Some(help) = required_value.help_text() {
format!("{}\nHelp: {}", base_message, help)
} else {
base_message
};
if warn_mode {
warn!("{}", message);
} else {
return Err(eyre!("{}", message));
}
}
}
Ok(())
}
fn parse_template(
&self,
ctx: &tera::Context,
tera: &mut tera::Tera,
path: &Path,
input: &str,
) -> eyre::Result<String> {
let mut output = input.to_string();
// Step 1: Tera template expansion
if input.contains("{{") || input.contains("{%") || input.contains("{#") {
trust_check(path)?;
output = tera
.render_str(input, ctx)
.wrap_err_with(|| eyre!("failed to parse template: '{input}'"))?;
}
// Step 2: Shell-style $VAR expansion
if output.contains('$') {
debug_assert!(
!env!("CARGO_PKG_VERSION").starts_with("2026.7"),
"change env_shell_expand default to true and remove this warning"
);
match Settings::get().env_shell_expand {
Some(true) => {
let env_vars: BTreeMap<String, String> = ctx
.get("env")
.and_then(|v| serde_json::from_value(v.clone()).ok())
.unwrap_or_default();
let before_expand = output.clone();
let mut missing_vars = Vec::new();
output = shellexpand::env_with_context_no_errors(&output, |var| match env_vars
.get(var)
{
Some(v) => Some(Cow::Borrowed(v.as_str())),
None => {
missing_vars.push(var.to_string());
None
}
})
.into_owned();
for var in missing_vars {
// Don't warn if the user provided a default via ${VAR:-...} or ${VAR-...}
if !before_expand.contains(&format!("${{{var}:-"))
&& !before_expand.contains(&format!("${{{var}-"))
{
warn_once!(
"env var '{var}' is not defined and will be left unexpanded. \
Use ${{{var}:-}} to default to an empty string and suppress \
this warning."
);
}
}
}
Some(false) => {}
None => {
warn_once!(
"env value contains '$' which will be expanded in a future release. \
Set `env_shell_expand = true` to opt in or `env_shell_expand = false` to \
keep current behavior and suppress this warning."
);
}
}
}
Ok(output)
}
pub fn is_empty(&self) -> bool {
self.env.is_empty()
&& self.vars.is_empty()
&& self.env_remove.is_empty()
&& self.env_files.is_empty()
&& self.env_paths.is_empty()
&& self.env_scripts.is_empty()
&& self.tool_add_paths.is_empty()
}
}
impl Debug for EnvResults {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut ds = f.debug_struct("EnvResults");
if !self.env.is_empty() {
ds.field("env", &self.env.keys().collect::<Vec<_>>());
}
if !self.vars.is_empty() {
ds.field("vars", &self.vars.keys().collect::<Vec<_>>());
}
if !self.env_remove.is_empty() {
ds.field("env_remove", &self.env_remove);
}
if !self.env_paths.is_empty() {
ds.field("env_paths", &self.env_paths);
}
if !self.env_scripts.is_empty() {
ds.field("env_scripts", &self.env_scripts);
}
if !self.tool_add_paths.is_empty() {
ds.field("tool_add_paths", &self.tool_add_paths);
}
ds.finish()
}
}