Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.

Commit b46a3d9

Browse files
committed
Add qe vars -q
1 parent c4dacbb commit b46a3d9

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/main.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ enum Command {
4949
///
5050
/// For example, use 'quickenv reload && eval "$(quickenv vars)"' to load the environment like
5151
/// direnv normally would.
52-
Vars,
52+
Vars {
53+
/// Quiet mode: print nothing if there is no .envrc
54+
#[clap(long, short)]
55+
quiet: bool,
56+
},
5357
/// Create a new shim binary in ~/.quickenv/bin/.
5458
///
5559
/// Executing that binary will run in the context of the nearest .envrc, as if it was activated
@@ -142,7 +146,7 @@ fn main_inner() -> Result<(), Error> {
142146

143147
match args.subcommand {
144148
Command::Reload => command_reload(),
145-
Command::Vars => command_vars(),
149+
Command::Vars { quiet } => command_vars(quiet),
146150
Command::Shim { commands, yes } => command_shim(commands, yes),
147151
Command::Unshim { commands } => command_unshim(commands),
148152
Command::Exec { program_name, args } => command_exec(program_name, args),
@@ -519,9 +523,16 @@ impl<'a> CheckUnshimmedCommands<'a> {
519523
}
520524
}
521525

522-
fn command_vars() -> Result<(), Error> {
526+
fn command_vars(quiet: bool) -> Result<(), Error> {
523527
let quickenv_home = crate::core::get_quickenv_home()?;
524-
let ctx = resolve_envrc_context(&quickenv_home)?;
528+
529+
let ctx = match resolve_envrc_context(&quickenv_home) {
530+
Ok(ctx) => ctx,
531+
Err(core::Error::NoEnvrc) if quiet => {
532+
return Ok(());
533+
}
534+
Err(e) => return Err(e.into()),
535+
};
525536

526537
if let Some(envvars) = core::get_envvars(&ctx)? {
527538
for (k, v) in envvars {
@@ -531,6 +542,8 @@ fn command_vars() -> Result<(), Error> {
531542
io::stdout().write_all(b"\n")?;
532543
}
533544

545+
Ok(())
546+
} else if quiet {
534547
Ok(())
535548
} else {
536549
log::error!(

tests/acceptance.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,26 @@ fn test_verbosity() -> Result<(), Error> {
166166
Ok(())
167167
}
168168

169+
#[test]
170+
fn test_vars_quiet() -> Result<(), Error> {
171+
let harness = setup()?;
172+
assert_cmd!(harness, quickenv "vars" "-q", @r###"
173+
success: true
174+
exit_code: 0
175+
----- stdout -----
176+
177+
----- stderr -----
178+
"###);
179+
assert_cmd!(harness, quickenv "vars" "--quiet", @r###"
180+
success: true
181+
exit_code: 0
182+
----- stdout -----
183+
184+
----- stderr -----
185+
"###);
186+
Ok(())
187+
}
188+
169189
#[test]
170190
fn test_script_failure() -> Result<(), Error> {
171191
let harness = setup()?;

0 commit comments

Comments
 (0)