Skip to content
Permalink
Browse files

skara: add -v, --version and -h, --help

Reviewed-by: rwestberg
  • Loading branch information
Erik Helin
Erik Helin committed Sep 4, 2020
1 parent dc3276d commit fd58cb63b0b5bbea0891f89a0362c39f933d0501
Showing with 21 additions and 4 deletions.
  1. +21 −4 cli/src/main/java/org/openjdk/skara/cli/GitSkara.java
@@ -32,21 +32,34 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.*;
import java.util.stream.Collectors;

public class GitSkara {
private static final Map<String, Main> commands = new TreeMap<>();
private static final Set<String> mercurialCommands = Set.of("webrev", "defpath", "jcheck");

private static void usage(String[] args) {
private static void help(String[] args) throws Exception {
var isMercurial = args.length > 0 && args[0].equals("--mercurial");
if (args.length > 0 && !isMercurial) {
var command = args[0];
if (commands.containsKey(command)) {
commands.get(command).main(new String[]{"-h"});
} else {
System.err.println("error: unknown command: " + command);
}
}

var skaraCommands = Set.of("help", "version", "update");

var names = new ArrayList<String>();
if (isMercurial) {
names.addAll(mercurialCommands);
names.addAll(skaraCommands);
} else {
names.addAll(commands.keySet());
names.addAll(commands.keySet().stream()
.filter(s -> !s.startsWith("-"))
.filter(s -> !s.equals("debug"))
.collect(Collectors.toList()));
}

var vcs = isMercurial ? "hg" : "git";
@@ -201,8 +214,12 @@ public static void main(String[] args) throws Exception {
commands.put("hg-export", GitHgExport::main);

commands.put("update", GitSkara::update);
commands.put("help", GitSkara::usage);
commands.put("-h", GitSkara::help);
commands.put("--help", GitSkara::help);
commands.put("help", GitSkara::help);
commands.put("version", GitSkara::version);
commands.put("--version", GitSkara::version);
commands.put("-v", GitSkara::version);

checkGitVersion();

@@ -213,7 +230,7 @@ public static void main(String[] args) throws Exception {
commands.get(command).main(commandArgs);
} else {
System.err.println("error: unknown command: " + command);
usage(args);
help(new String[0]);
}
}
}

1 comment on commit fd58cb6

@bridgekeeper

This comment has been minimized.

Copy link

@bridgekeeper bridgekeeper bot commented on fd58cb6 Sep 4, 2020

Please sign in to comment.