-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from jfdenise/cli-v2
Re-work CLI
- Loading branch information
Showing
28 changed files
with
1,037 additions
and
152 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
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
44 changes: 44 additions & 0 deletions
44
cli/src/main/java/org/wildfly/glow/cli/ExecutionExceptionHandler.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,44 @@ | ||
/* | ||
* Copyright 2022 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.wildfly.glow.cli; | ||
|
||
import picocli.CommandLine; | ||
|
||
|
||
/** | ||
* Handles exceptions that happen during command executions. | ||
*/ | ||
public class ExecutionExceptionHandler implements CommandLine.IExecutionExceptionHandler { | ||
|
||
private final boolean isVerbose; | ||
|
||
public ExecutionExceptionHandler(boolean isVerbose) { | ||
this.isVerbose = isVerbose; | ||
} | ||
|
||
@Override | ||
public int handleExecutionException(Exception ex, CommandLine commandLine, CommandLine.ParseResult parseResult) | ||
throws Exception { | ||
System.err.println(CommandLine.Help.Ansi.AUTO.string("@|fg(red) ERROR: " + ex.getLocalizedMessage() + "|@")); | ||
if(isVerbose) { | ||
ex.printStackTrace(); | ||
} | ||
return 1; | ||
} | ||
|
||
} |
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
38 changes: 38 additions & 0 deletions
38
cli/src/main/java/org/wildfly/glow/cli/commands/AbstractCommand.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,38 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2023 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.wildfly.glow.cli.commands; | ||
|
||
import java.util.Optional; | ||
import java.util.concurrent.Callable; | ||
|
||
import picocli.CommandLine; | ||
|
||
public abstract class AbstractCommand implements Callable<Integer> { | ||
|
||
@SuppressWarnings("unused") | ||
@CommandLine.Option( | ||
names = {Constants.HELP_OPTION_SHORT, Constants.HELP_OPTION}, | ||
usageHelp = true | ||
) | ||
boolean help; | ||
|
||
@SuppressWarnings("unused") | ||
@CommandLine.Option( | ||
names = {Constants.VERBOSE_OPTION_SHORT, Constants.VERBOSE_OPTION} | ||
) | ||
Optional<Boolean> verbose; | ||
} |
46 changes: 46 additions & 0 deletions
46
cli/src/main/java/org/wildfly/glow/cli/commands/CompletionCommand.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,46 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2023 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.wildfly.glow.cli.commands; | ||
|
||
import picocli.AutoComplete; | ||
import picocli.CommandLine; | ||
|
||
/** | ||
* By invoking this command, user can obtain a shell completion script. | ||
* | ||
* User can apply the completion script by running `source <(wildfly-glow completion)` (in bash), or can redirect the | ||
* output of this command to a file. | ||
* | ||
* The completion script can be used for bash and zsh. | ||
*/ | ||
@CommandLine.Command( | ||
name = Constants.COMPLETION_COMMAND, | ||
mixinStandardHelpOptions = true, | ||
helpCommand = true) | ||
public class CompletionCommand implements Runnable { | ||
|
||
@CommandLine.Spec | ||
CommandLine.Model.CommandSpec spec; | ||
|
||
@Override | ||
public void run() { | ||
String script = AutoComplete.bash(Constants.WILDFLY_GLOW, spec.root().commandLine()); | ||
spec.commandLine().getOut().print(script); | ||
spec.commandLine().getOut().print('\n'); | ||
spec.commandLine().getOut().flush(); | ||
} | ||
} |
Oops, something went wrong.