Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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]);
}
}
}