class VulasCli {

  public static void main(String[] _args)
      throws GoalConfigurationException, GoalExecutionException {

    // Prepare parsing of cmd line arguments
    final Options options = new Options();
    options.addOption(
        "goal",
        "goal",
        true,
        "Goal to be executed (clean, cleanSpace, app, a2c, t2c, instr, report, upload)");

    // Get the goal to be executed
    try {
      final CommandLineParser parser = new DefaultParser();
      final CommandLine cmd = parser.parse(options, _args);
      String g = cmd.getOptionValue("goal", null);

      // Ugly workaround to correct the non-intuitive goal type SPACECLEAN and SPACEDEL
      // TODO: Change GoalType.SPACECLEAN and GoalType.SPACEDEL
      if ("cleanSpace".equals(g)) g = "spaceClean";
      else if ("cleanSpace".equals(g)) g = "spaceDel";

      goalType = GoalType.parseGoal(g);
    }
    // Happens for unknown/invalid options
    catch (ParseException pe) {
      log.error(pe.getMessage());
      final HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp("Vulas Command Line Interface", options);
      return;
    }
    // Happens during the parsing of the goal
    catch (IllegalArgumentException iae) {
      log.error(iae.getMessage());
      final HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp("Vulas Command Line Interface", options);
      return;
    }

    // Create and execute the goal
    try {
      goal = GoalFactory.create(goalType, GoalClient.CLI);
      goal.executeSync();
    } catch (IllegalStateException ise) {
      log.error(ise.getMessage());
    } catch (IllegalArgumentException iae) {
      log.error(iae.getMessage());
    }
  }

}