szetszwo commented on a change in pull request #603: URL: https://github.com/apache/ratis/pull/603#discussion_r811181167
########## File path: ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/ElectionCommand.java ########## @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.ratis.shell.cli.sh.command; + +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.ratis.shell.cli.Command; +import org.apache.ratis.shell.cli.sh.election.PauseCommand; +import org.apache.ratis.shell.cli.sh.election.ResumeCommand; +import org.apache.ratis.shell.cli.sh.election.TransferCommand; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class ElectionCommand extends AbstractRatisCommand{ + + private static final List<Function<Context, AbstractRatisCommand>> SUB_COMMAND_CONSTRUCTORS + = Collections.unmodifiableList(Arrays.asList( + TransferCommand::new, PauseCommand::new, ResumeCommand::new)); + + private final Map<String, Command> subs; + public static final String ADDRESS_OPTION_NAME = "address"; + + /** + * @param context command context + */ + public ElectionCommand(Context context) { + super(context); + this.subs = Collections.unmodifiableMap(SUB_COMMAND_CONSTRUCTORS.stream() + .map(constructor -> constructor.apply(context)) + .collect(Collectors.toMap(Command::getCommandName, Function.identity()))); + } + + @Override + public String getCommandName() { + return "election"; + } + + @Override + public String getUsage() { + + StringBuilder usage = new StringBuilder(getCommandName()); + for (String cmd : subs.keySet()) { + usage.append(" [").append(cmd).append("]"); + } + return usage.toString(); + } Review comment: If we add the following code, ``` +++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/RatisShell.java @@ -39,6 +39,9 @@ public class RatisShell extends AbstractShell { */ public static void main(String[] args) { RatisShell extensionShell = new RatisShell(); + if (args.length == 0) { + extensionShell.printUsage(); + } System.exit(extensionShell.run(args)); } ``` it will print out `[election [resume] [transfer] [pause]] ` under `[generic options]` as shown below. ``` Usage: ratis sh [generic options] [election [resume] [transfer] [pause]] [group [list] [info]] [peer -peers <PEER0_HOST:PEER0_PORT,PEER1_HOST:PEER1_PORT,PEER2_HOST:PEER2_PORT> [-groupid <RAFT_GROUP_ID>] -remove <PEER_HOST:PEER_PORT> -add <PEER_HOST:PEER_PORT>] [setPriority -peers <PEER0_HOST:PEER0_PORT,PEER1_HOST:PEER1_PORT,PEER2_HOST:PEER2_PORT> [-groupid <RAFT_GROUP_ID>] -addressPriority <PEER_HOST:PEER_PORT|PRIORITY>] [snapshot [create]] Usage: ratis sh [generic options] [election [resume] [transfer] [pause]] [group [list] [info]] [peer -peers <PEER0_HOST:PEER0_PORT,PEER1_HOST:PEER1_PORT,PEER2_HOST:PEER2_PORT> [-groupid <RAFT_GROUP_ID>] -remove <PEER_HOST:PEER_PORT> -add <PEER_HOST:PEER_PORT>] [setPriority -peers <PEER0_HOST:PEER0_PORT,PEER1_HOST:PEER1_PORT,PEER2_HOST:PEER2_PORT> [-groupid <RAFT_GROUP_ID>] -addressPriority <PEER_HOST:PEER_PORT|PRIORITY>] [snapshot [create]] ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
