Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub struct BaseArgs {
#[arg(long, short = 'v', env = "BRAINTRUST_VERBOSE", global = true, conflicts_with = "quiet", value_parser = clap::builder::BoolishValueParser::new(), default_value_t = false)]
pub verbose: bool,

#[arg(skip)]
pub verbose_source: Option<ArgValueSource>,

/// Reduce interactive UI output
#[arg(long, short = 'q', env = "BRAINTRUST_QUIET", global = true, value_parser = clap::builder::BoolishValueParser::new(), default_value_t = false)]
pub quiet: bool,
Expand Down Expand Up @@ -118,6 +121,10 @@ impl BaseArgs {
pub fn ca_cert(&self) -> Option<&Path> {
self.ca_cert.as_deref()
}

pub fn verbose_explicit(&self) -> bool {
self.verbose && self.verbose_source.is_some()
}
}

pub fn has_explicit_profile_arg(args: &[OsString]) -> bool {
Expand Down
1 change: 1 addition & 0 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3251,6 +3251,7 @@ mod tests {
BaseArgs {
json: false,
verbose: false,
verbose_source: None,
quiet: false,
quiet_source: None,
no_color: false,
Expand Down
1 change: 1 addition & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ mod tests {
BaseArgs {
json: false,
verbose: false,
verbose_source: None,
quiet: false,
quiet_source: None,
no_color: false,
Expand Down
1 change: 1 addition & 0 deletions src/functions/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3589,6 +3589,7 @@ mod tests {
BaseArgs {
json: false,
verbose: false,
verbose_source: None,
quiet: false,
quiet_source: None,
no_color: false,
Expand Down
32 changes: 32 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ fn try_main() -> Result<()> {
}

fn apply_base_arg_sources(matches: &ArgMatches, base: &mut BaseArgs) {
base.verbose_source = find_value_source(matches, "verbose").and_then(map_value_source);
base.quiet_source = find_value_source(matches, "quiet").and_then(map_value_source);
base.api_key_source = find_value_source(matches, "api_key").and_then(map_value_source);
}
Expand Down Expand Up @@ -501,6 +502,37 @@ mod tests {
assert_eq!(cli.command.base().api_key_source, None);
}

#[test]
fn apply_base_arg_sources_tracks_cli_verbose() {
let matches = Cli::command()
.try_get_matches_from(["bt", "sync", "pull", "--verbose"])
.expect("matches");
let mut cli = Cli::from_arg_matches(&matches).expect("cli");

apply_base_arg_sources(&matches, cli.command.base_mut());

assert_eq!(
cli.command.base().verbose_source,
Some(ArgValueSource::CommandLine)
);
assert!(cli.command.base().verbose_explicit());
}

#[test]
fn default_verbose_output_is_not_explicit_verbose() {
let matches = Cli::command()
.try_get_matches_from(["bt", "sync", "pull"])
.expect("matches");
let mut cli = Cli::from_arg_matches(&matches).expect("cli");

apply_base_arg_sources(&matches, cli.command.base_mut());
apply_base_output_defaults(&mut cli.command);

assert!(cli.command.base().verbose);
assert_eq!(cli.command.base().verbose_source, None);
assert!(!cli.command.base().verbose_explicit());
}

#[test]
fn apply_base_output_defaults_keeps_setup_quiet_by_default() {
let matches = Cli::command()
Expand Down
1 change: 1 addition & 0 deletions src/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4955,6 +4955,7 @@ mod tests {
BaseArgs {
json: false,
verbose: false,
verbose_source: None,
quiet: false,
quiet_source: None,
no_color: false,
Expand Down
1 change: 1 addition & 0 deletions src/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ mod tests {
BaseArgs {
json: false,
verbose: false,
verbose_source: None,
quiet: false,
quiet_source: None,
no_color: false,
Expand Down
Loading
Loading