mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
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
This commit is contained in:
parent
c0e195e144
commit
b6f3d60e0f
1 changed files with 12 additions and 9 deletions
|
@ -118,6 +118,17 @@ final class RegistryCli {
|
||||||
}
|
}
|
||||||
loggingParams.configureLogging(); // Must be called after parameters are parsed.
|
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.
|
// Create the main component and use it to inject the command class.
|
||||||
RegistryToolComponent component = DaggerRegistryToolComponent.builder()
|
RegistryToolComponent component = DaggerRegistryToolComponent.builder()
|
||||||
.flagsModule(new AppEngineConnectionFlags.FlagsModule(appEngineConnectionFlags))
|
.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..
|
// Get the App Engine connection, advise the user if they are not currently logged in..
|
||||||
AppEngineConnection connection;
|
AppEngineConnection connection = component.appEngineConnection();
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command instanceof ServerSideCommand) {
|
if (command instanceof ServerSideCommand) {
|
||||||
((ServerSideCommand) command).setConnection(connection);
|
((ServerSideCommand) command).setConnection(connection);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue