-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve nb、mqtt and coap help and version information
- Loading branch information
1 parent
ca96060
commit 1894a99
Showing
10 changed files
with
107 additions
and
45 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
22 changes: 22 additions & 0 deletions
22
...ain/java/iot/technology/client/toolkit/common/commandline/CommandErrorMessageHandler.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,22 @@ | ||
package iot.technology.client.toolkit.common.commandline; | ||
|
||
import picocli.CommandLine; | ||
|
||
import java.io.PrintWriter; | ||
|
||
/** | ||
* @author mushuwei | ||
*/ | ||
public class CommandErrorMessageHandler extends CommonErrorMessageHandler | ||
implements CommandLine.IParameterExceptionHandler { | ||
|
||
@Override | ||
public int handleParseException(CommandLine.ParameterException ex, String[] args) throws Exception { | ||
final int exitCode = super.handleParseException(ex, args); | ||
final CommandLine cmd = ex.getCommandLine(); | ||
final PrintWriter writer = cmd.getErr(); | ||
final CommandLine.Model.CommandSpec spec = cmd.getCommandSpec(); | ||
writer.printf("Try '%s --help' for more information.%n", spec.qualifiedName()); | ||
return exitCode; | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...main/java/iot/technology/client/toolkit/common/commandline/CommonErrorMessageHandler.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,37 @@ | ||
package iot.technology.client.toolkit.common.commandline; | ||
|
||
import picocli.CommandLine; | ||
|
||
import java.io.PrintWriter; | ||
|
||
/** | ||
* @author mushuwei | ||
*/ | ||
public abstract class CommonErrorMessageHandler implements CommandLine.IParameterExceptionHandler { | ||
|
||
@Override | ||
public int handleParseException(CommandLine.ParameterException ex, String[] args) throws Exception { | ||
printErrorMessage(ex); | ||
|
||
return generateExitCode(ex); | ||
} | ||
|
||
private void printErrorMessage(final CommandLine.ParameterException parameterException) { | ||
final PrintWriter writer = parameterException.getCommandLine().getErr(); | ||
|
||
if (parameterException.getCause() != null) { | ||
writer.println(parameterException.getMessage() | ||
.replace(parameterException.getCause().toString(), parameterException.getCause().getMessage())); | ||
} else { | ||
writer.println(parameterException.getMessage()); | ||
} | ||
} | ||
|
||
private int generateExitCode(final CommandLine.ParameterException parameterException) { | ||
final CommandLine cmd = parameterException.getCommandLine(); | ||
final CommandLine.Model.CommandSpec spec = cmd.getCommandSpec(); | ||
return cmd.getExitCodeExceptionMapper() != null ? | ||
cmd.getExitCodeExceptionMapper().getExitCode(parameterException) : | ||
spec.exitCodeOnInvalidInput(); | ||
} | ||
} |
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