-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow specifying a default action for the launcher
Will be used when no arguments are provided. Ignored when invoked via javaw which will always open the GUI.
- Loading branch information
Showing
6 changed files
with
203 additions
and
28 deletions.
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
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
51 changes: 51 additions & 0 deletions
51
src/main/java/software/coley/recaf/launch/commands/SetDefaultAction.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,51 @@ | ||
package software.coley.recaf.launch.commands; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Parameters; | ||
import software.coley.recaf.launch.util.Config; | ||
|
||
import java.util.Set; | ||
import java.util.TreeSet; | ||
import java.util.concurrent.Callable; | ||
|
||
/** | ||
* Command for specifying a default action to run, which will be used when invoking the launcher with no arguments | ||
* in any following execution. | ||
*/ | ||
@Command(name = "set-default-action", description = "Allows specifying a default action to run when no arguments are specified. " + | ||
"For commands with spaces in them, surround the whole command with quotes.") | ||
public class SetDefaultAction implements Callable<Void> { | ||
private static final Logger logger = LoggerFactory.getLogger(SetDefaultAction.class); | ||
|
||
@Parameters(index = "0", description = "The action to run. Should match one of the launcher commands.") | ||
private String action; | ||
|
||
@Override | ||
public Void call() { | ||
if ("set-default-action".equals(action)) { | ||
logger.error("You cannot set the default action to be a recursive setting of the default action"); | ||
return null; | ||
} | ||
|
||
// Collect commands. | ||
Set<String> commandNames = new TreeSet<>(); | ||
Command rootCommand = Root.class.getDeclaredAnnotation(Command.class); | ||
Class<?>[] subcommands = rootCommand.subcommands(); | ||
for (Class<?> subcommand : subcommands) { | ||
commandNames.add(subcommand.getDeclaredAnnotation(Command.class).name()); | ||
} | ||
|
||
// Set it if it matches. | ||
if (commandNames.contains(action)) { | ||
Config.getInstance().setDefaultAction(action); | ||
} else { | ||
logger.error("The value '" + action + "' did not match any existing command name.\n" + | ||
"The available commands are:\n" + | ||
" - " + String.join("\n - ", commandNames)); | ||
} | ||
|
||
return null; | ||
} | ||
} |
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
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
Oops, something went wrong.