// Copyright 2016 The Nomulus Authors. 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 google.registry.tools; import static google.registry.security.JsonHttp.JSON_SAFETY_PREFIX; import static google.registry.tools.server.ListObjectsAction.FIELDS_PARAM; import static google.registry.tools.server.ListObjectsAction.FULL_FIELD_NAMES_PARAM; import static google.registry.tools.server.ListObjectsAction.PRINT_HEADER_ROW_PARAM; import com.beust.jcommander.Parameter; import com.google.common.base.VerifyException; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; import google.registry.tools.Command.RemoteApiCommand; import java.util.List; import java.util.Map; import javax.annotation.Nullable; import org.json.simple.JSONValue; /** * Abstract base class for commands that list objects by calling a server task. * *
The formatting is done on the server side; this class just dumps the results to the screen.
*/
abstract class ListObjectsCommand implements RemoteApiCommand, ServerSideCommand {
@Nullable
@Parameter(
names = {"-f", "--fields"},
description = "Comma-separated list of fields to show for each object listed")
private String fields;
@Nullable
@Parameter(
names = {"--header"},
description = "Whether or not to print a header row for the resulting output - default is to "
+ "only print headers when more than one column is output",
arity = 1)
private Boolean printHeaderRow;
@Parameter(
names = {"--full_field_names"},
description = "Whether to print full field names in header row (as opposed to aliases)")
private boolean fullFieldNames = false;
private Connection connection;
@Override
public void setConnection(Connection connection) {
this.connection = connection;
}
/** Returns the path to the servlet task. */
abstract String getCommandPath();
/** Returns a map of parameters to be sent to the server
* (in addition to the usual ones). */
@Nullable
ImmutableMap