From 55cc7b22a41709819b706f9aa74eb6e4f0d1e5e8 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Tue, 28 Apr 2020 23:18:02 -0700 Subject: [PATCH] fix: fixes origin not being parsed for subcommands --- src/config.rs | 37 +++++++++++++++++++++++++++---------- src/utils/args.rs | 1 + 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index 3714cb8758..75a9d495d7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -268,16 +268,33 @@ impl Config { /// Given a match object from clap, this returns the org from it. pub fn get_org(&self, matches: &ArgMatches<'_>) -> Result { - Ok(matches - .value_of("org") - .map(str::to_owned) - .or_else(|| env::var("SENTRY_ORG").ok()) - .or_else(|| { - self.ini - .get_from(Some("defaults"), "org") - .map(str::to_owned) - }) - .ok_or_else(|| err_msg("An organization slug is required (provide with --org)"))?) + // Recursively check the commands and subcommands until "org" + // is found. If none is found check the env var or throw an error. + if let Some(org) = matches.value_of("org") { + Ok(org.to_owned()) + } else { + match matches.subcommand_name() { + Some(subcommand) => { + if let Some(sub_matches) = matches.subcommand_matches(subcommand) { + self.get_org(sub_matches) + } else { + Err(err_msg( + "An organization slug is required (provide with --org)", + )) + } + } + None => env::var("SENTRY_ORG") + .ok() + .or_else(|| { + self.ini + .get_from(Some("defaults"), "org") + .map(str::to_owned) + }) + .ok_or_else(|| { + err_msg("An organization slug is required (provide with --org)") + }), + } + } } /// Given a match object from clap, this returns a tuple in the diff --git a/src/utils/args.rs b/src/utils/args.rs index 6ec13ad6a6..7b86df695f 100644 --- a/src/utils/args.rs +++ b/src/utils/args.rs @@ -112,6 +112,7 @@ impl<'a: 'b, 'b> ArgExt for clap::App<'a, 'b> { .value_name("ORG") .long("org") .short("o") + .global(true) .validator(validate_org) .help("The organization slug"), )