From b6f3d60e0f51b85ef39e6486b7d5295713faf4df Mon Sep 17 00:00:00 2001 From: mmuller Date: Mon, 6 Mar 2017 12:20:03 -0800 Subject: [PATCH] Refactor command running around auth exceptions Refactor command and component code in RegistryCli so that we can handle a LoginRequiredException from whereever we are likely to ever get one. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=149329171 --- java/google/registry/tools/RegistryCli.java | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/java/google/registry/tools/RegistryCli.java b/java/google/registry/tools/RegistryCli.java index 4cefe89ef..0a7bc0f49 100644 --- a/java/google/registry/tools/RegistryCli.java +++ b/java/google/registry/tools/RegistryCli.java @@ -118,6 +118,17 @@ final class RegistryCli { } loggingParams.configureLogging(); // Must be called after parameters are parsed. + try { + runCommand(command); + } catch (AuthModule.LoginRequiredException ex) { + System.err.println("==================================================================="); + System.err.println("You must login using 'nomulus login' prior to running this command."); + System.err.println("==================================================================="); + return; + } + } + + private void runCommand(Command command) throws Exception { // Create the main component and use it to inject the command class. RegistryToolComponent component = DaggerRegistryToolComponent.builder() .flagsModule(new AppEngineConnectionFlags.FlagsModule(appEngineConnectionFlags)) @@ -132,15 +143,7 @@ final class RegistryCli { } // Get the App Engine connection, advise the user if they are not currently logged in.. - AppEngineConnection connection; - try { - connection = component.appEngineConnection(); - } catch (AuthModule.LoginRequiredException ex) { - System.err.println("==================================================================="); - System.err.println("You must login using 'nomulus login' prior to running this command."); - System.err.println("==================================================================="); - return; - } + AppEngineConnection connection = component.appEngineConnection(); if (command instanceof ServerSideCommand) { ((ServerSideCommand) command).setConnection(connection);