MCPcopy Create free account
hub / github.com/TrsstProject/trsst / doBegin

Method doBegin

src/main/java/com/trsst/Command.java:422–514  ·  view source on GitHub ↗
(String[] argv, PrintStream out, InputStream in)

Source from the content-addressed store, hash-verified

420 }
421
422 public int doBegin(String[] argv, PrintStream out, InputStream in) {
423
424 buildOptions(argv, out, in);
425
426 int result = 0;
427 Server server = null;
428 try {
429
430 CommandLineParser argParser = new GnuParser();
431 CommandLine commands;
432 try {
433 commands = argParser.parse(mergedOptions, argv);
434 } catch (Throwable t) {
435 log.error(
436 "Unexpected error parsing arguments: "
437 + Arrays.asList(argv), t);
438 return 127;
439 }
440 LinkedList<String> arguments = new LinkedList<String>();
441 for (Object o : commands.getArgList()) {
442 arguments.add(o.toString()); // dodge untyped param warning
443 }
444 if (commands.hasOption("?")) {
445 printAllUsage();
446 return 0;
447 }
448 if (arguments.size() < 1) {
449 printAllUsage();
450 return 127; // "command not found"
451 }
452 if (!commands.hasOption("strict")) {
453 // most trsst nodes run with self-signed certificates,
454 // so by default we accept them
455 Common.enableAnonymousSSL();
456 } else {
457 System.err.println("Requiring signed SSL");
458 }
459 // System.out.println("Commands: " + arguments );
460 String mode = arguments.removeFirst().toString();
461
462 // for port requests
463 if ("serve".equals(mode)) {
464 // start a server and exit
465 result = doServe(commands, arguments);
466 return 0;
467 }
468
469 // attempt to parse next argument as a server url
470 Client client = null;
471 if (commands.hasOption("h")) {
472 String host = commands.getOptionValue("h");
473 try {
474 URL url = new URL(host);
475 // this argument is a server url
476 client = new Client(url);
477 System.err.println("Using service: " + host);
478 } catch (MalformedURLException e) {
479 // otherwise: ignore and continue

Callers 2

mainMethod · 0.80
doPostMethod · 0.80

Calls 10

buildOptionsMethod · 0.95
printAllUsageMethod · 0.95
enableAnonymousSSLMethod · 0.95
doServeMethod · 0.95
getServiceURLMethod · 0.95
doPullMethod · 0.95
doPushMethod · 0.95
doPostMethod · 0.95
stopMethod · 0.95
equalsMethod · 0.80

Tested by

no test coverage detected