Skip to content

Commit

Permalink
Add uim.errors dependency and refactor plugin command argument handling
Browse files Browse the repository at this point in the history
  • Loading branch information
UIMSolutions committed Feb 5, 2025
1 parent e41fcd4 commit 19cfda5
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 205 deletions.
27 changes: 17 additions & 10 deletions commands/uim/commands/classes/plugins/load.d
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DPluginLoadCommand : DCommand {
DConsoleOptionParser buildOptionParser(DConsoleOptionParser parser) {
with (parser) {
description("Command for loading plugins.");
addArgument("plugin", MapHelper.create!(string, Json)
/* addArgument("plugin", MapHelper.create!(string, Json)
.set("help", "Name of the plugin to load. Must be in CamelCase format. Example: uim plugin load Example")
.set("required", true)
);
Expand All @@ -105,22 +105,29 @@ class DPluginLoadCommand : DCommand {
.set("boolean", true)
.set("help", "Load the plugin only for CLI.")
);
addOption("optional", MapHelper.create!(string, Json)
.set("boolean", true)
.set("help", "Do not throw an error if the plugin is not available.")
);
Json[string] optional;
optional.set("boolean", true);
optional.set("help", "Do not throw an error if the plugin is not available.");
addOption("optional", optional);
Json[string] noBootstrap;
addOption("no-bootstrap", MapHelper.create!(string, Json)
.set("boolean", true)
.set("help", "Do not run the `bootstrap()` hook.")
);
Json[string] noConsole;
addOption("no-console", MapHelper.create!(string, Json)
.set("boolean", true)
.set("help", "Do not run the `console()` hook.")
);
addOption("no-middleware", MapHelper.create!(string, Json)
.set("boolean", true)
.set("help", "Do not run the `middleware()` hook..")
);
Json[string] noMiddleware;
noMiddleware.set("boolean", true);
noMiddleware.set("help", "Do not run the `middleware()` hook..");
addOption("no-middleware", noMiddleware);
Json[string] noRoutes;
addOption("no-routes", MapHelper.create!(string, Json)
.set("boolean", true)
.set("help", "Do not run the `routes()` hook.")
Expand All @@ -129,7 +136,7 @@ class DPluginLoadCommand : DCommand {
.set("boolean", true)
.set("help", "Do not run the `services()` hook.")
);

*/
}
return parser;
}
Expand Down
8 changes: 4 additions & 4 deletions commands/uim/commands/classes/plugins/unload.d
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class DPluginUnloadCommand : DCommand {
DConsoleOptionParser buildOptionParser(DConsoleOptionParser parsertoUpdate) {
parsertoUpdate.description("Command for unloading plugins.");

parsertoUpdate.addArgument("plugin", MapHelper.create!(string, Json)
.set("help", "Name of the plugin to unload.")
.set("required", true)
);
Json[string] map;
map.set("help", "Name of the plugin to unload.");
map.set("required", true);
parsertoUpdate.addArgument("plugin", map);

return parsertoUpdate;
}
Expand Down
103 changes: 103 additions & 0 deletions core/uim/core/convert/json.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
module uim.core.convert.json;

import uim.core;
@safe:

version (test_uim_core) {
unittest {
writeln("----- ", __MODULE__, "\t -----");
}
}

// #region toJson
Json toJson(bool value) {
return Json(value);
}

Json toJson(long value) {
return Json(value);
}

Json toJson(double value) {
return Json(value);
}

Json toJson(string value) {
return Json(value);
}

Json toJson(UUID value) {
return toJson(value.toString);
}

Json toJson(string aKey, string aValue) {
Json result = Json.emptyObject;
result[aKey] = aValue;
return result;
}

unittest {
assert(toJson("a", "3")["a"] == "3");
}

Json toJson(string aKey, UUID aValue) {
Json result = Json.emptyObject;
result[aKey] = aValue.toString;
return result;
}

unittest {
auto id = randomUUID;
assert(UUID(toJson("id", id)["id"].get!string) == id);
}

/// Special case for managing entities
Json toJson(UUID id, size_t versionNumber) {
Json result = toJson("id", id);
result["versionNumber"] = versionNumber;
return result;
}

unittest {
auto id = randomUUID;
assert(toJson(id, 0).getString("id") == id.toString);
assert("versionNumber" in toJson(id, 0));
assert(toJson(id, 1)["id"].get!string == id.toString);
assert(toJson(id, 1)["versionNumber"].get!size_t == 1);
}

Json toJson(bool[] values) {
auto json = Json.emptyArray;
values.each!(value => json ~= value);
return json;
}

unittest {
assert([true, true, false].toJson.length == 3);
assert([true, true, false].toJson[0].getBoolean);
}

Json toJson(string[] values) {
auto json = Json.emptyArray;
values.each!(value => json ~= value);
return json;
}

unittest {
assert(["a", "b", "c"].toJson.length == 3);
assert(["a", "b", "c"].toJson[0] == "a");
}

Json toJson(string[string] map, string[] excludeKeys = null) {
Json json = Json.emptyObject;
map.byKeyValue
.filter!(kv => !excludeKeys.any!(key => key == kv.key))
.each!(kv => json[kv.key] = kv.value);
return json;
}

unittest {
assert(["a": "1", "b": "2", "c": "3"].toJson.length == 3);
assert(["a": "1", "b": "2", "c": "3"].toJson["a"] == "1");
}
// #endregion toJson
1 change: 1 addition & 0 deletions core/uim/core/convert/package.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module uim.core.convert;

public {
import uim.core.convert.json;
import uim.core.convert.jsonmap;
import uim.core.convert.string_;
}
92 changes: 0 additions & 92 deletions core/uim/core/datatypes/json/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -1060,98 +1060,6 @@ unittest {
}
// #endregion setter

// #region toJson
Json toJson(bool value) {
return Json(value);
}

Json toJson(long value) {
return Json(value);
}

Json toJson(double value) {
return Json(value);
}

Json toJson(string value) {
return Json(value);
}

Json toJson(UUID value) {
return toJson(value.toString);
}

Json toJson(string aKey, string aValue) {
Json result = Json.emptyObject;
result[aKey] = aValue;
return result;
}

unittest {
assert(toJson("a", "3")["a"] == "3");
}

Json toJson(string aKey, UUID aValue) {
Json result = Json.emptyObject;
result[aKey] = aValue.toString;
return result;
}

unittest {
auto id = randomUUID;
assert(UUID(toJson("id", id)["id"].get!string) == id);
}

/// Special case for managing entities
Json toJson(UUID id, size_t versionNumber) {
Json result = toJson("id", id);
result["versionNumber"] = versionNumber;
return result;
}

unittest {
auto id = randomUUID;
assert(toJson(id, 0).getString("id") == id.toString);
assert("versionNumber" in toJson(id, 0));
assert(toJson(id, 1)["id"].get!string == id.toString);
assert(toJson(id, 1)["versionNumber"].get!size_t == 1);
}

Json toJson(bool[] values) {
auto json = Json.emptyArray;
values.each!(value => json ~= value);
return json;
}

unittest {
assert([true, true, false].toJson.length == 3);
assert([true, true, false].toJson[0].getBoolean);
}

Json toJson(string[] values) {
auto json = Json.emptyArray;
values.each!(value => json ~= value);
return json;
}

unittest {
assert(["a", "b", "c"].toJson.length == 3);
assert(["a", "b", "c"].toJson[0] == "a");
}

Json toJson(string[string] map, string[] excludeKeys = null) {
Json json = Json.emptyObject;
map.byKeyValue
.filter!(kv => !excludeKeys.any!(key => key == kv.key))
.each!(kv => json[kv.key] = kv.value);
return json;
}

unittest {
assert(["a": "1", "b": "2", "c": "3"].toJson.length == 3);
assert(["a": "1", "b": "2", "c": "3"].toJson["a"] == "1");
}
// #endregion toJson

Json match(K)(Json[K] matchValues, K key, Json defaultValue = Json(null)) {
return key in matchValues
Expand Down
1 change: 1 addition & 0 deletions css/dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependency "vibe-d" version="~>0.10.0"

dependency "uim:core" path="../"
dependency "uim:oop" path="../"
dependency "uim:errors" path="../"

sourcePaths "."
importPaths "."
Expand Down
1 change: 1 addition & 0 deletions css/uim/css/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public {
public { // Required uim libraries
import uim.core;
import uim.oop;
import uim.errors;

// import uim.filesystems;
// import uim.models;
Expand Down
Loading

0 comments on commit 19cfda5

Please sign in to comment.