-
Notifications
You must be signed in to change notification settings - Fork 418
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
Add support for globally registering color schemes #516
Comments
Thanks for raising this. To clarify, is it all of the following methods that do not behave as expected?
Can you please show steps to reproduce the issue? |
I think the main issue I'm hitting is that I cannot globally centralize the @Command(
name = "test",
mixinStandardHelpOptions = true,
subcommands = {
HelpCommand.class, // myCustomColorScheme below doesn't propagate here
MyCommand.class})
public class AllCommand extends AbstractCommand {
@Override
public Status call() {
commandSpec.commandLine()
.usage(System.out, myCustomColorScheme);
return super.call();
} doesn't result in a consistent theme because /** Invokes {@link #usage(PrintStream, Help.Ansi) usage} for the specified command, or for the parent command. */
public void run() {
...
} else {
parent.usage(out, ansi);
}
} where public void usage(PrintStream out, Help.Ansi ansi) { usage(out, Help.defaultColorScheme(ansi)); } and |
Thanks for the clarification. I understand the problem now. |
I think the problem is that in the convenience methods (run, call, invoke), there is support for specifying an To support this, the static If the above is added, it should be possible for an application to have a consistent color scheme everywhere in the command hierarchy by simply calling:
|
Additionally, a new interface
|
The existing convenience methods ( Please verify. |
I may partially revert this commit. CommandLine cmd = new CommandLine(new MyRunnable())
.setOut(createOutPrintWriter()) // System.out by default
.setErr(createErrPrintWriter()) // System.err by default
.setColorScheme(createColorScheme()); // default color scheme by default
int exitCode = cmd.execute(args);
//System.exit(exitCode); I will likely deprecate the |
… configured ColorScheme also refactored some duplicate code
Right now it doesn't appear to be possible to globally set an
CommandLine.Help.ColorScheme
and have this be consistently applied to an application. A common example is when using subcommands and anHelpCommand
. If the parent command modifies the color scheme, this doesn't propagate to thehelp
command.As a workaround, one can do something similar to:
But this is less than ideal from a localization and overriding perspective.
The text was updated successfully, but these errors were encountered: