package com.cadrlife.devsearch.agent;
import com.cadrlife.devsearch.agent.action.*;
import joptsimple.OptionException;
import org.eclipse.jgit.util.FS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Guice;
import com.google.inject.Injector;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
public class Main {
private static Logger LOG = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) {
try {
System.exit(exec(System.in, System.out, System.err, args));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
static int exec(InputStream in, PrintStream out, PrintStream err, String[] args) throws IOException {
AgentActions agentActions = new AgentActions();
agentActions.add(new UpdateIndexAction()).add(new CheckoutAction()).add(new UpdateContentsAction()).add(new UpdateIndexAction());
if (args.length == 0 || !agentActions.isKnownAction(args[0])) {
out.println("Usage: dev-search-agent <action> <options>");
out.println("Available actions:");
for (String availableActionName : agentActions.getActionNames()) {
out.println(" " + availableActionName);
}
out.println("Args " + Arrays.asList(args));
return 1;
}
String actionName = args[0];
AgentAction selectedAction = agentActions.findAction(actionName);
AgentModule agentModule = new AgentModule();
try {
showBanner(out);
out.println("Usage: dev-search-agent <action> <options>");
out.println("Action " + actionName + ":");
selectedAction.execute(args, agentModule);
} catch (OptionException e) {
selectedAction.printHelpOn(out);
out.println(e.getMessage());
return 1;
}
LOG.debug("User Home {}", FS.DETECTED.userHome().getAbsolutePath());
//
// if (options.has("exclude")) {
// agent.clean(updateScope);
// }
// if (options.has("clean")) {
// agent.clean(updateScope);
// }
//
// if (options.has("pull-from-source")) {
// agent.pullFromSourceAsync(updateScope);
// }
//
// if (options.has(executeOption)) {
// agent.executeScript(updateScope, options.valueOf(executeOption));
// }
//
// if (options.has("list-projects")) {
// agent.listProjects(updateScope);
// }
// if (options.has("push-to-repo")) {
// agent.pushToRepo(updateScope);
// }
// if (options.has("list-projects")) {
// agent.listProjects(updateScope);
// }
// String repoName = "repo-springsource-github";
// Injector injector = Guice.createInjector(new CodeSearchModule());
// LocalRepoCrawler repoCrawler = injector.getInstance(LocalRepoCrawler.class);
//// LocalRepoCrawler repoCrawler = injector.getInstance(LocalRepoCrawler.class);
// repoCrawler.walkRepo(repoName);
return 0;
}
private static void showBanner(PrintStream out) {
out.println(
"________ _________ .__ _____ __ \n" +
"\\______ \\ ____ ___ __ / _____/ ____ _____ _______ ____ | |__ / _ \\ ____ ____ ____ _/ |_ \n" +
" | | \\ _/ __ \\ \\ \\/ / \\_____ \\ _/ __ \\ \\__ \\ \\_ __ \\_/ ___\\ | | \\ / /_\\ \\ / ___\\ _/ __ \\ / \\ \\ __\\\n" +
" | ` \\\\ ___/ \\ / / \\\\ ___/ / __ \\_ | | \\/\\ \\___ | Y \\ / | \\ / /_/ >\\ ___/ | | \\ | | \n" +
"/_______ / \\___ > \\_/ /_______ / \\___ >(____ / |__| \\___ >|___| / \\____|__ / \\___ / \\___ >|___| / |__| \n" +
" \\/ \\/ \\/ \\/ \\/ \\/ \\/ \\/ /_____/ \\/ \\/ ");
}
}