Skip to content

Commit da7cd48

Browse files
committed
Added case for successful retrieval with no matches.
1 parent 2a72cc8 commit da7cd48

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

src/main/java/org/hydev/mcpm/client/commands/controllers/ListController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,15 @@ public void listAll(String parameter, Consumer<String> log) {
6363

6464
try {
6565
var list = listAllBoundary.listAll(listType);
66-
ListResult queryResult = new ListResult(list, ListResult.Type.SUCCESS_RETRIEVING_LOCAL_AND_UPDATABLE);
67-
listPresenter.displayResult(queryResult);
66+
67+
// if list is empty
68+
if (list.isEmpty()) {
69+
ListResult queryResult = new ListResult(list, ListResult.Type.SUCCESS_RETRIEVING_BUT_NO_MATCHES);
70+
listPresenter.displayResult(queryResult);
71+
} else {
72+
ListResult queryResult = new ListResult(list, ListResult.Type.SUCCESS_RETRIEVING_LOCAL_AND_UPDATABLE);
73+
listPresenter.displayResult(queryResult);
74+
}
6875
} catch (Exception e) {
6976
ListResult queryResult = new ListResult(null, ListResult.Type.SEARCH_FAILED_TO_FETCH_INSTALLED);
7077
listPresenter.displayResult(queryResult);

src/main/java/org/hydev/mcpm/client/display/presenters/ListPresenter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public void displayResult(ListResult listResult) {
3333
var table = tabulate(
3434
list.stream().map(p -> List.of("&a" + p.name(), "&e" + p.getFirstAuthor(), p.version())).toList(),
3535
List.of(":Name", "Author", "Version:"));
36-
this.log.accept(listResult.type().reason() + "\n" + table);
36+
37+
this.log.accept(listResult.type().reason() + "\n" + table);
38+
3739
}
3840
}
3941
}

src/main/java/org/hydev/mcpm/client/list/ListResult.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public enum Type {
1818
SEARCH_FAILED_TO_FETCH_INSTALLED("Failed to fetch local files."),
1919
SUCCESS_RETRIEVING_LOCAL_BUT_FAIL_UPDATABLE("Successfully retrieved local files," +
2020
" but failed to retrieve updatable files."),
21-
SUCCESS_RETRIEVING_LOCAL_AND_UPDATABLE("Successfully retrieved local files.");
21+
SUCCESS_RETRIEVING_LOCAL_AND_UPDATABLE("Successfully retrieved local files."),
22+
SUCCESS_RETRIEVING_BUT_NO_MATCHES("Successfully retrieved local files, but no matches found.");
2223

2324
private final String reason;
2425

src/main/java/org/hydev/mcpm/client/list/ListUpdatableHelper.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ public ArrayList<String> listUpdatable(
4747
PluginModelId pluginModelId = new PluginModelId(
4848
OptionalLong.of(installedModel.getPluginId()), installedModel.getName(), null);
4949

50-
temp.add(new PluginVersionState(pluginModelId, pluginVersionId));
50+
try {
51+
temp.add(new PluginVersionState(pluginModelId, pluginVersionId));
52+
} catch (Exception e) {
53+
break;
54+
}
5155
}
5256

5357
CheckForUpdatesInput input = new CheckForUpdatesInput(temp, false);
54-
5558
CheckForUpdatesResult rawResult = checkForUpdatesBoundary.updates(input);
5659

5760
// Read the list of installedModels and create a CheckForUpdatesInput object
@@ -60,7 +63,7 @@ public ArrayList<String> listUpdatable(
6063

6164
if (rawResult.state() == CheckForUpdatesResult.State.SUCCESS) {
6265

63-
// get the ids of the plugins that are outdated from result
66+
// get the names of the plugins that are outdated from result
6467
ArrayList<String> outdated = new ArrayList<>();
6568
for (PluginModel pluginModel : rawResult.updatable().values()) {
6669
pluginModel.getLatestPluginVersion()

0 commit comments

Comments
 (0)