Skip to content

Commit 57f23d6

Browse files
committed
improve code and nb help
1 parent 891962b commit 57f23d6

File tree

16 files changed

+179
-118
lines changed

16 files changed

+179
-118
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>
8585
<maven-jar-plugin.version>3.2.2</maven-jar-plugin.version>
8686
<jreleaser.version>1.1.0</jreleaser.version>
87+
<opencsv.version>5.7.1</opencsv.version>
8788
</properties>
8889

8990
<dependencyManagement>
@@ -173,6 +174,11 @@
173174
<artifactId>okhttp</artifactId>
174175
<version>${okhttp.version}</version>
175176
</dependency>
177+
<dependency>
178+
<groupId>com.opencsv</groupId>
179+
<artifactId>opencsv</artifactId>
180+
<version>${opencsv.version}</version>
181+
</dependency>
176182
</dependencies>
177183
</dependencyManagement>
178184

toolkit-app/src/main/java/iot/technology/client/toolkit/app/ToolKitCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public Integer call() {
107107

108108
// toolkit config simple description
109109
sb.append(String.format("%s %s", bundle.getString("config.description"),
110-
"(" + bundle.getString("general.reference") + ColorUtils.redBold("toolkit config -h", "red") + ")"))
110+
"(" + bundle.getString("general.reference") + ColorUtils.colorBold("toolkit config -h", "red") + ")"))
111111
.append(StringUtils.lineSeparator());
112112
sb.append(String.format("%s %s", "locale ",
113113
bundle.getString("config.lang.header") + " " + bundle.getString("config.locale")))
@@ -116,7 +116,7 @@ public Integer call() {
116116

117117
// toolkit coap simple description
118118
sb.append(String.format("%s %s", bundle.getString("coap.description"),
119-
"(" + bundle.getString("general.reference") + ColorUtils.redBold("toolkit coap -h", "red") + ")"))
119+
"(" + bundle.getString("general.reference") + ColorUtils.colorBold("toolkit coap -h", "red") + ")"))
120120
.append(StringUtils.lineSeparator());
121121
sb.append(String.format("%s %s", "disc: ", bundle.getString("coap.disc.description")))
122122
.append(StringUtils.lineSeparator());
@@ -132,7 +132,7 @@ public Integer call() {
132132

133133
// toolkit mqtt simple description
134134
sb.append(String.format("%s %s", bundle.getString("mqtt.description"),
135-
"(" + bundle.getString("general.reference") + ColorUtils.redBold("toolkit mqtt -h", "red") + ")"))
135+
"(" + bundle.getString("general.reference") + ColorUtils.colorBold("toolkit mqtt -h", "red") + ")"))
136136
.append(StringUtils.lineSeparator());
137137
sb.append(String.format("%s %s", "publish: ", bundle.getString("mqtt.pub.description")))
138138
.append(StringUtils.lineSeparator());
@@ -142,7 +142,7 @@ public Integer call() {
142142

143143
// toolkit nb simple description
144144
sb.append(String.format("%s %s", bundle.getString("nb.description"),
145-
"(" + bundle.getString("general.reference") + ColorUtils.redBold("toolkit nb -h", "red") + ")"))
145+
"(" + bundle.getString("general.reference") + ColorUtils.colorBold("toolkit nb -h", "red") + ")"))
146146
.append(StringUtils.lineSeparator());
147147
sb.append(String.format("%s %s", "call: ", bundle.getString("nb.call.desc")))
148148
.append(StringUtils.lineSeparator());

toolkit-app/src/main/resources/i18n/messages.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ mqtt.select.config.error=please enter 0,1,2... or new
138138
##NB settings
139139
nb.header=NB-IoT Client Toolkit
140140
nb.description= user-friendly NB-IoT client toolkit
141+
nb.settings.list.desc=display all nb settings list
142+
nb.settings.del.desc=delete nb settings with the specified serial number
143+
nb.settings.add.desc=add nb settings
144+
nb.settings.show.desc=display nb settings details
141145

142146
##NB prompt
143147
nbType.prompt=Please select the Nb-IoT type

toolkit-app/src/main/resources/i18n/messages_de.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ mqtt.select.config.error=bitte 0,1,2... oder neu eingeben
136136
##NB settings
137137
nb.header=NB-IoT Client Toolkit
138138
nb.description=benutzerfreundliches NB-IoT-Client-Toolkit
139+
nb.settings.list.desc=zeigt alle nb-Einstellungslisten an
140+
nb.settings.del.desc=nb-Einstellungen mit der angegebenen Seriennummer löschen
141+
nb.settings.add.desc=nb-Einstellungen hinzufügen
142+
nb.settings.show.desc=Details zu nb-Einstellungen anzeigen
139143

140144
##NB prompt
141145
nbType.prompt=Please select the Nb-IoT type

toolkit-app/src/main/resources/i18n/messages_fr.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ mqtt.select.config.error=veuillez entrer 0,1,2... ou nouveau
137137
##NB settings
138138
nb.header=NB-IoT Client Toolkit
139139
nb.description=boîte à outils client NB-IoT conviviale
140+
nb.settings.list.desc=display all nb settings list
141+
nb.settings.del.desc=delete nb settings with the specified serial number
142+
nb.settings.add.desc=add nb settings
143+
nb.settings.show.desc=display nb settings details
140144

141145
##NB prompt
142146
nbType.prompt=Please select the Nb-IoT type

toolkit-app/src/main/resources/i18n/messages_zh.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ mqtt.select.config.error=\u8bf7\u8f93\u51650,1,2...\u6216new
132132

133133
##NB settings
134134
nb.header=NB-IoT \u5ba2\u6237\u7aef\u5de5\u5177\u5305
135-
nb.description=\u7528\u6237\u53cb\u597d\u7684 NB-IoT \u5ba2\u6237\u7aef\u5de5\u5177\u5305
135+
nb.description=\u7528\u6237\u53cb\u597d\u7684 nb-iot \u5ba2\u6237\u7aef\u5de5\u5177\u5305
136+
nb.settings.list.desc=\u5c55\u793a\u6240\u6709\u7684\u914d\u7f6e\u5217\u8868
137+
nb.settings.del.desc=\u5220\u9664\u6307\u5b9a\u5e8f\u53f7\u7684\u914d\u7f6e
138+
nb.settings.add.desc=\u589e\u52a0nb-iot\u914d\u7f6e
139+
nb.settings.show.desc=\u5c55\u793anb-iot\u914d\u7f6e\u8be6\u60c5
136140

137141
##NB prompt
138142
nbType.prompt=\u8bf7\u9009\u62e9 Nb-IoT \u5e73\u53f0

toolkit-coap/src/main/java/iot/technology/client/toolkit/coap/command/CoapCommand.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import iot.technology.client.toolkit.coap.command.sub.*;
1919
import iot.technology.client.toolkit.common.constants.ExitCodeEnum;
2020
import iot.technology.client.toolkit.common.constants.StorageConstants;
21+
import iot.technology.client.toolkit.common.utils.StringUtils;
2122
import picocli.CommandLine;
2223

2324
import java.util.ResourceBundle;
@@ -54,13 +55,22 @@ public class CoapCommand implements Callable<Integer> {
5455

5556
@Override
5657
public Integer call() {
57-
System.out.format("describe, desc: " + colorItalic(bundle.getString("coap.desc.description"), "cyan") + "%n");
58-
System.out.format("media-type, mt: " + colorItalic(bundle.getString("coap.media.types.description"), "cyan") + "%n");
59-
System.out.format("discover, disc: " + colorItalic(bundle.getString("coap.disc.description"), "cyan") + "%n");
60-
System.out.format("get: " + colorItalic(bundle.getString("coap.get.description"), "cyan") + "%n");
61-
System.out.format("post: " + colorItalic(bundle.getString("coap.post.description"), "cyan") + "%n");
62-
System.out.format("put: " + colorItalic(bundle.getString("coap.put.description"), "cyan") + "%n");
63-
System.out.format("delete, del: " + colorItalic(bundle.getString("coap.del.description"), "cyan") + "%n");
58+
StringBuilder sb = new StringBuilder();
59+
sb.append("describe, desc: ").append(colorItalic(bundle.getString("coap.desc.description"), "cyan"))
60+
.append(StringUtils.lineSeparator());
61+
sb.append("media-type, mt: ").append(colorItalic(bundle.getString("coap.media.types.description"), "cyan"))
62+
.append(StringUtils.lineSeparator());
63+
sb.append("discover, disc: ").append(colorItalic(bundle.getString("coap.disc.description"), "cyan"))
64+
.append(StringUtils.lineSeparator());
65+
sb.append("get: ").append(colorItalic(bundle.getString("coap.get.description"), "cyan"))
66+
.append(StringUtils.lineSeparator());
67+
sb.append("post: ").append(colorItalic(bundle.getString("coap.post.description"), "cyan"))
68+
.append(StringUtils.lineSeparator());
69+
sb.append("put: ").append(colorItalic(bundle.getString("coap.put.description"), "cyan"))
70+
.append(StringUtils.lineSeparator());
71+
sb.append("delete, del: ").append(colorItalic(bundle.getString("coap.del.description"), "cyan"))
72+
.append(StringUtils.lineSeparator());
73+
System.out.println(sb);
6474
return ExitCodeEnum.SUCCESS.getValue();
6575
}
6676

toolkit-coap/src/main/java/iot/technology/client/toolkit/coap/command/sub/CoapDiscoverCommand.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import iot.technology.client.toolkit.coap.validator.CoapCommandParamValidator;
2020
import iot.technology.client.toolkit.common.constants.ExitCodeEnum;
2121
import iot.technology.client.toolkit.common.constants.StorageConstants;
22+
import iot.technology.client.toolkit.common.utils.StringUtils;
2223
import org.eclipse.californium.core.CoapClient;
2324
import org.eclipse.californium.core.WebLink;
2425
import picocli.CommandLine;
@@ -28,8 +29,6 @@
2829
import java.util.Set;
2930
import java.util.concurrent.Callable;
3031

31-
import static iot.technology.client.toolkit.coap.service.CoapClientService.green;
32-
3332
/**
3433
* @author mushuwei
3534
*/
@@ -64,9 +63,11 @@ public Integer call() throws Exception {
6463

6564
Set<WebLink> webLinks = coapClient.discover();
6665
String availableResources = coapClientService.getAvailableResources(webLinks);
67-
String header = String.format("==================== %s ====================", bundle.getString("coap.available.resources"));
68-
System.out.format(green(header) + "%n");
69-
System.out.println(availableResources);
66+
StringBuilder sb = new StringBuilder();
67+
sb.append(String.format("==================== %s ====================", bundle.getString("coap.available.resources")))
68+
.append(StringUtils.lineSeparator());
69+
sb.append(availableResources).append(StringUtils.lineSeparator());
70+
System.out.println(sb);
7071
return ExitCodeEnum.SUCCESS.getValue();
7172
}
7273
}

toolkit-coap/src/main/java/iot/technology/client/toolkit/coap/command/sub/CoapMediaTypesCommand.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
import iot.technology.client.toolkit.coap.service.CoapClientService;
1919
import iot.technology.client.toolkit.common.constants.ExitCodeEnum;
2020
import iot.technology.client.toolkit.common.constants.StorageConstants;
21-
import org.eclipse.californium.core.coap.MediaTypeRegistry;
21+
import iot.technology.client.toolkit.common.utils.ColorUtils;
22+
import iot.technology.client.toolkit.common.utils.StringUtils;
2223
import picocli.CommandLine;
2324

2425
import java.util.ResourceBundle;
2526
import java.util.concurrent.Callable;
2627

27-
import static iot.technology.client.toolkit.coap.service.CoapClientService.green;
28-
2928
/**
3029
* @author mushuwei
3130
*/
@@ -49,11 +48,13 @@ public class CoapMediaTypesCommand implements Callable<Integer> {
4948

5049
@Override
5150
public Integer call() throws Exception {
52-
MediaTypeRegistry mediaTypeRegistry = new MediaTypeRegistry();
51+
5352
String supportedMediaTypes = coapClientService.getSupportedMediaTypes();
53+
StringBuilder sb = new StringBuilder();
5454
String header = String.format("==================== %s ====================", bundle.getString("coap.media.types"));
55-
System.out.format(green(header) + "%n");
56-
System.out.println(supportedMediaTypes);
55+
sb.append(ColorUtils.colorBold(header, "green")).append(StringUtils.lineSeparator());
56+
sb.append(supportedMediaTypes).append(StringUtils.lineSeparator());
57+
System.out.println(sb);
5758
return ExitCodeEnum.SUCCESS.getValue();
5859
}
5960

toolkit-coap/src/main/java/iot/technology/client/toolkit/coap/command/sub/CoapPutCommand.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import iot.technology.client.toolkit.coap.service.CoapClientService;
1919
import iot.technology.client.toolkit.coap.validator.CoapCommandParamValidator;
2020
import iot.technology.client.toolkit.common.constants.ExitCodeEnum;
21-
import iot.technology.client.toolkit.common.constants.HelpVersionGroup;
2221
import org.eclipse.californium.core.CoapClient;
2322
import org.eclipse.californium.core.CoapResponse;
2423
import picocli.CommandLine;
@@ -43,8 +42,8 @@ public class CoapPutCommand implements Callable<Integer> {
4342

4443
private final CoapClientService coapClientService = new CoapClientService();
4544

46-
@CommandLine.ArgGroup
47-
HelpVersionGroup helpVersionGroup;
45+
@CommandLine.Option(names = {"-h", "--help"}, usageHelp = true, description = "${bundle:general.help.description}")
46+
boolean usageHelpRequested;
4847

4948
@CommandLine.Parameters(
5049
index = "0",

0 commit comments

Comments
 (0)