google-nomulus/java/com/google/domain/registry/tools/GtechTool.java
nickfelt 5174c1c63f Improve RegistryToolEnvironment setup behavior
Here's an alternate approach that I think simplifies the existing
code quite a bit.  Now instead of doing:

  RegistryToolEnvironment.loadFromArgs(args);
  RegistryToolEnvironment.get().setup();

You just do one chained call:

  RegistryToolEnvironment.parseFromArgs(args).setup();

or call setup() on a known environment constant:

  RegistryToolEnvironment.ALPHA.setup();

This avoids having loadFromArgs() implicitly set the active env
(but *not* do setup) and then having setup() *not* set the active
env, both of which were confusing.  Now parseFromArgs() is only
responsible for parsing from args, and setup() both sets the env
as the active one and does the environment variable setup (which
also ensures that the RegistryToolEnvironment.instance field
doesn't get out of sync with the RegistryEnvironment value).

In addition, this CL adds a runCommandInEnvironment() method to
CommandTestCase and ensures that the UNITTEST environment is always
set before constructing the default command instance.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117492978
2016-03-23 22:38:08 -04:00

78 lines
4 KiB
Java

// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.domain.registry.tools;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap;
import com.google.domain.registry.tools.Command.GtechCommand;
/** Command line interface with a subset of commands that are safe for tech support to run. */
public final class GtechTool {
/**
* Commands that exist in both {@link GtechTool} and {@link RegistryTool}.
*
* <p><b>Note:</b> If changing the command-line name of any commands below, remember to resolve
* any invocations in scripts (e.g. PDT, ICANN reporting).
*/
static final ImmutableMap<String, Class<? extends GtechCommand>> COMMAND_MAP =
ImmutableSortedMap.<String, Class<? extends GtechCommand>>naturalOrder()
.put("auction_status", AuctionStatusCommand.class)
.put("canonicalize_labels", CanonicalizeLabelsCommand.class)
.put("convert_idn", ConvertIdnCommand.class)
.put("create_anchor_tenant", CreateAnchorTenantCommand.class)
.put("create_contact", CreateContactCommand.class)
.put("create_registrar_groups", CreateRegistrarGroupsCommand.class)
.put("create_registrar", CreateRegistrarCommand.class)
.put("create_sandbox_tld", CreateSandboxTldCommand.class)
.put("delete_domain", DeleteDomainCommand.class)
.put("domain_application_info", DomainApplicationInfoCommand.class)
.put("domain_check", DomainCheckCommand.class)
.put("domain_check_claims", DomainCheckClaimsCommand.class)
.put("domain_check_fee", DomainCheckFeeCommand.class)
.put("generate_applications_report", GenerateApplicationsReportCommand.class)
.put("generate_auction_data", GenerateAuctionDataCommand.class)
.put("generate_dns_report", GenerateDnsReportCommand.class)
.put("get_application", GetApplicationCommand.class)
.put("get_application_ids", GetApplicationIdsCommand.class)
.put("get_applied_labels", GetAppliedLabelsCommand.class)
.put("get_contact", GetContactCommand.class)
.put("get_domain", GetDomainCommand.class)
.put("get_history_entries", GetHistoryEntriesCommand.class)
.put("get_host", GetHostCommand.class)
.put("get_registrar", GetRegistrarCommand.class)
.put("get_schema", GetSchemaCommand.class)
.put("get_tld", GetTldCommand.class)
.put("hash_certificate", HashCertificateCommand.class)
.put("list_credits", ListCreditsCommand.class)
.put("list_registrars", ListRegistrarsCommand.class)
.put("list_tlds", ListTldsCommand.class)
.put("publish_detail_report", PublishDetailReportCommand.class)
.put("registrar_activity_report", RegistrarActivityReportCommand.class)
.put("registrar_contact", RegistrarContactCommand.class)
.put("setup_ote", SetupOteCommand.class)
.put("update_registrar", UpdateRegistrarCommand.class)
.put("update_sandbox_tld", UpdateSandboxTldCommand.class)
.put("update_server_locks", UpdateServerLocksCommand.class)
.put("validate_login_credentials", ValidateLoginCredentialsCommand.class)
.put("verify_ote", VerifyOteCommand.class)
.put("whois_query", WhoisQueryCommand.class)
.build();
public static void main(String[] args) throws Exception {
RegistryToolEnvironment.parseFromArgs(args).setup();
new RegistryCli().run("gtech_tool", args, COMMAND_MAP);
}
}