package org.karaffe.compiler.phase.util;

import org.karaffe.compiler.phase.Phase;
import org.karaffe.compiler.util.CompilerContext;
import org.karaffe.compiler.util.args.Flag;
import org.karaffe.compiler.util.args.ParameterName;
import org.karaffe.compiler.util.report.Report;
import org.karaffe.compiler.util.report.ReportCode;

import java.util.Objects;

public class ShowUsagePhase implements Phase {

  private final Flag[] supportedFlags;
  private final ParameterName[] supportedParameterNames;

  public ShowUsagePhase() {
    this.supportedFlags = new Flag[0];
    this.supportedParameterNames = new ParameterName[0];
  }

  public ShowUsagePhase(Flag[] supportedFlags, ParameterName[] supportedParameterNames) {
    this.supportedFlags = Objects.requireNonNull(supportedFlags);
    this.supportedParameterNames = Objects.requireNonNull(supportedParameterNames);
  }

  @Override
  public String getName() {
    return "show-usage";
  }

  @Override
  public void execute(CompilerContext context) {
    StringBuilder stringBuilder = new StringBuilder();
    for (Flag flag : supportedFlags) {
      stringBuilder.append(flag.toFullString()).append(System.lineSeparator());
    }
    context.add(Report.newReport(ReportCode.INFO_COMPILER_INTERNAL_USAGE).withBody(stringBuilder.toString()).build());
  }
}

@@ -1060,91 +1060,372 @@
 ();%0A
-    for (Flag flag : supportedFlags) %7B%0A      stringBuilder.append(flag.toFullString
+%0A    int maxWidthLeft = 0;%0A    for (Flag flag : supportedFlags) %7B%0A      maxWidthLeft = Math.max(flag.toFullString().length(), maxWidthLeft);%0A    %7D%0A%0A    maxWidthLeft += 2;%0A%0A    String formatText = %22%25-%22 + maxWidthLeft + %22s%22;%0A%0A    for (Flag flag : supportedFlags) %7B%0A      stringBuilder.append(String.format(formatText, flag.toFullString())).append(flag.getDescription
 ()).

Update usage