Skip to content

Commit c3e3bab

Browse files
committed
util.args: print required options explicitly in command usage
1 parent d864062 commit c3e3bab

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/printer/BinaryGraphPrinter.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ public BinaryGraphPrinter(DebugContext ctx, SnippetReflectionProvider snippetRef
106106

107107
@SuppressWarnings("this-escape")
108108
public BinaryGraphPrinter(WritableByteChannel channel, SnippetReflectionProvider snippetReflection) throws IOException {
109-
this.output = GraphOutput.newBuilder(this).
110-
blocks(this).
111-
elementsAndLocations(this, this).
112-
types(this).build(channel);
109+
this.output = GraphOutput.newBuilder(this).blocks(this).elementsAndLocations(this, this).types(this).build(channel);
113110
this.snippetReflection = snippetReflection;
114111
}
115112

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/util/args/Command.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,35 @@ private void verifyOptions(int nextPositionalArg) throws MissingArgumentExceptio
223223
}
224224
}
225225

226-
public void printUsage(PrintWriter writer) {
227-
writer.append(getName());
228-
if (!named.isEmpty()) {
226+
protected void printOptionUsage(PrintWriter writer) {
227+
boolean optionalFound = false;
228+
var it = named.getEntries();
229+
while (it.advance()) {
230+
if (it.getValue().isRequired()) {
231+
writer.append(String.format(" %s %s", it.getKey(), it.getValue().getUsage()));
232+
} else {
233+
optionalFound = true;
234+
}
235+
}
236+
if (optionalFound) {
229237
writer.append(" [OPTIONS]");
230238
}
239+
231240
for (OptionValue<?> option : positional) {
232241
writer.append(' ');
233-
writer.append(option.getUsage());
242+
if (option.isRequired()) {
243+
writer.append(option.getUsage());
244+
} else {
245+
writer.append(String.format("[%s]", option.getUsage()));
246+
}
234247
}
235248
}
236249

250+
public void printUsage(PrintWriter writer) {
251+
writer.append(getName());
252+
printOptionUsage(writer);
253+
}
254+
237255
public final void printHelp(PrintWriter writer) {
238256
printHelp(writer, 0);
239257
}

0 commit comments

Comments
 (0)