コード例 #1
0
 @Override
 public void run(final Context context) throws ExitException {
   if (context.contains(INSTANCE)) {
     context.show("Validating DSL ...");
     final Either<Boolean> result = DslCompiler.parse(context, DslPath.getDslPaths(context));
     if (result.isSuccess()) {
       context.show("Parse successful.");
     } else {
       context.error(result.whyNot());
       throw new ExitException();
     }
   }
 }
コード例 #2
0
ファイル: Main.java プロジェクト: ngs-doo/dsl-compiler-client
 private static void showHelpAndExit(
     final Context context, final boolean headers, final List<CompileParameter> parameters) {
   if (headers) {
     context.show("DSL Platform - Command-Line Client (" + Main.getVersion() + ")");
     context.show(
         "This tool allows you to compile provided DSL to various languages such as Java, Scala, PHP, C#, etc... or create an SQL migration between two DSL models.");
   }
   context.show();
   context.show();
   context.show("Command parameters:");
   int max = 0;
   for (final CompileParameter cp : parameters) {
     if (cp.getShortDescription() == null) {
       continue;
     }
     int width = cp.getAlias().length();
     if (cp.getUsage() != null) {
       width += 1 + cp.getUsage().length();
     }
     if (max < width) {
       max = width;
     }
   }
   max += 2;
   for (final CompileParameter cp : parameters) {
     if (cp.getShortDescription() == null) {
       continue;
     }
     final StringBuilder sb = new StringBuilder();
     sb.append(" -").append(cp.getAlias());
     int len = max - cp.getAlias().length();
     if (cp.getUsage() != null) {
       sb.append("=").append(cp.getUsage());
       len -= cp.getUsage().length() + 1;
     }
     for (; len >= 0; len--) {
       sb.append(' ');
     }
     sb.append(cp.getShortDescription());
     context.show(sb.toString());
   }
   context.show();
   context.show("Example usages:");
   context.show("\ttarget=java_client,revenj.java postgres=localhost/Database?user=postgres");
   context.show(
       "\tjava_client=model.jar revenj.net=Model.dll postgres=localhost/Database?user=postgres");
   context.show("\tproperties=development.props download");
 }
コード例 #3
0
ファイル: Main.java プロジェクト: ngs-doo/dsl-compiler-client
 public static boolean processContext(
     final Context context, final List<CompileParameter> parameters) {
   try {
     context.notify("PROCESS", parameters);
     for (final CompileParameter cp : parameters) {
       if (!cp.check(context)) {
         if (cp.getDetailedDescription() != null) {
           context.show();
           context.show();
           context.show(cp.getDetailedDescription());
         }
         return false;
       }
     }
     for (final CompileParameter cp : parameters) {
       cp.run(context);
     }
     return true;
   } catch (ExitException ex) {
     return false;
   }
 }