-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve noargs message and add a help argument + detailed message #188
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f24c1ee
Initial ideas for improved help message
sschr15 1186e98
Undo small unnecessary change in older code
sschr15 590f976
Separate the main function into its own class
sschr15 4818262
I forgot to update the main class
sschr15 138aab2
Undo moving entire main class separately
sschr15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/org/jetbrains/java/decompiler/main/decompiler/ConsoleHelp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package org.jetbrains.java.decompiler.main.decompiler; | ||
|
||
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class ConsoleHelp { | ||
private static final String[] DEFAULT_HELP = { | ||
"Usage: java -jar quiltflower.jar [-<option>=<value>]* [<source>]+ <destination>", | ||
"At least one source file or directory must be specified.", | ||
"Options:", | ||
"--help: Show this help", | ||
"", "Saving options", | ||
"A maximum of one of the options can be specified:", | ||
"--file - Write the decompiled source to a file", | ||
"--folder - Write the decompiled source to a folder", | ||
"--legacy-saving - Use the legacy console-specific method of saving", | ||
"If unspecified, the decompiled source will be automatically detected based on destination name.", | ||
"", "General options", | ||
"These options can be specified multiple times.", | ||
"-e=<path> - Add the specified path to the list of external libraries", | ||
"-only=<class> - Only decompile the specified class", | ||
"", "Additional options", | ||
"These options take the last specified value.", | ||
"They each are specified with a three-character name followed by an equals sign, followed by the value.", | ||
"Booleans are traditionally indicated with `0` or `1`, but may also be specified with `true` or `false`.", | ||
"Because of this, an option indicated as a boolean may actually be a number." | ||
// Options are added at runtime | ||
}; | ||
|
||
static void printHelp() { | ||
for (String line : DEFAULT_HELP) { | ||
System.out.println(line); | ||
} | ||
|
||
List<Field> fields = Arrays.stream(IFernflowerPreferences.class.getDeclaredFields()) | ||
.filter(field -> field.getType() == String.class) | ||
.collect(Collectors.toList()); | ||
|
||
Map<String, Object> defaults = IFernflowerPreferences.DEFAULTS; | ||
|
||
for (Field field : fields) { | ||
IFernflowerPreferences.Name name = field.getAnnotation(IFernflowerPreferences.Name.class); | ||
IFernflowerPreferences.Description description = field.getAnnotation(IFernflowerPreferences.Description.class); | ||
|
||
String paramName; | ||
try { | ||
paramName = (String) field.get(null); | ||
} catch (IllegalAccessException e) { | ||
continue; | ||
} | ||
|
||
if (paramName.length() != 3) { | ||
continue; | ||
} | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
sb.append("-").append(paramName).append("=<"); | ||
|
||
String type; | ||
String defaultValue = (String) defaults.get(paramName); | ||
if (defaultValue == null) { | ||
sb.append("string>"); | ||
type = null; | ||
} else if (defaultValue.equals("0") || defaultValue.equals("1")) { | ||
sb.append("bool> "); | ||
type = "bool"; | ||
} else { | ||
try { | ||
Integer.parseInt(defaultValue); | ||
sb.append("int> "); | ||
type = "int"; | ||
} catch (NumberFormatException e) { | ||
sb.append("string>"); | ||
type = "string"; | ||
} | ||
} | ||
|
||
sb.append(" - "); | ||
|
||
if (name != null) { | ||
sb.append(name.value()); | ||
} else { | ||
sb.append(field.getName()); | ||
} | ||
|
||
if (description != null) { | ||
sb.append(": ").append(description.value()); | ||
} | ||
|
||
if (type != null) { | ||
sb.append(" (default: "); | ||
switch (type) { | ||
case "bool": | ||
sb.append(defaultValue.equals("1")); | ||
break; | ||
case "int": | ||
sb.append(defaultValue); | ||
break; | ||
case "string": | ||
sb.append('"').append(defaultValue).append('"'); | ||
break; | ||
} | ||
sb.append(")"); | ||
} | ||
|
||
System.out.println(sb); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The content of this if body should be moved out to another method (or maybe even another class) because the main method is getting very long