From dc8fd64a49afafde254aa411da8fe11e7de4ceea Mon Sep 17 00:00:00 2001 From: duansizhao Date: Wed, 29 Apr 2026 20:59:35 +0800 Subject: [PATCH] Co-Authored-By: Agent Signed-off-by: duansizhao Change-Id: I5eb8f28e5a2f7acc6256de6350b88456b1d8c46a --- tools/ohos-example/config.json | 37 +++++++++++++-------------------- tools/ohos-example/src/main.cpp | 36 +++++++++++++++++++++++--------- tools/ohos-simple/config.json | 34 ------------------------------ tools/ohos-simple/src/main.cpp | 17 +++++++++++++-- tools/ohos-timer/config.json | 19 +++-------------- tools/ohos-timer/src/main.cpp | 21 +++++++++++++++---- 6 files changed, 75 insertions(+), 89 deletions(-) diff --git a/tools/ohos-example/config.json b/tools/ohos-example/config.json index 0c411094fe..8114e36ea1 100644 --- a/tools/ohos-example/config.json +++ b/tools/ohos-example/config.json @@ -4,11 +4,19 @@ "description": "Example CLI tool, demonstrates CLI tool specification implementation (with subcommand format)", "executablePath": "/system/bin/cli_tool/executable/ohos-example", "hasSubcommands": true, - "timeout": 30, "requirePermissions": [], + "inputSchema": { + "type": "object", + "properties": {} + }, + "outputSchema": { + "type": "object", + "properties": {} + }, "subcommands": { "run": { "description": "Run example tool, execute and return results", + "requirePermissions": [], "inputSchema": { "type": "object", "properties": { @@ -28,23 +36,15 @@ } } }, - "eventTypes": ["progress", "result"], + "eventTypes": ["progress"], "eventSchemas": { - "result": { - "type": "object", - "description": "Execution result event", - "properties": { - "result": { - "type": "string", - "description": "Execution result string" - } - }, - "required": ["result"] - }, "progress": { "type": "object", "description": "Execution progress event", "properties": { + "type": { + "const": "progress" + }, "percentage": { "type": "integer", "minimum": 0, @@ -58,14 +58,11 @@ }, "required": ["percentage", "status"] } - }, - "argMapping": { - "type": "positional", - "order": ["argLine"] } }, "version": { "description": "Display version information", + "requirePermissions": [], "inputSchema": { "type": "object", "properties": { @@ -89,12 +86,6 @@ } }, "required": ["version"] - }, - "argMapping": { - "type": "flag", - "templates": { - "reserved": "--reserved={value}" - } } } } diff --git a/tools/ohos-example/src/main.cpp b/tools/ohos-example/src/main.cpp index ea472c848e..4cb278ac75 100644 --- a/tools/ohos-example/src/main.cpp +++ b/tools/ohos-example/src/main.cpp @@ -26,25 +26,41 @@ namespace { void EmitProgress(int percentage, const std::string& status) { - std::cout << "{\"event\": \"progress\", \"data\": {" + std::cout << "{\"type\": \"progress\", " << "\"percentage\": " << percentage << ", " << "\"status\": \"" << status << "\"" - << "}}" << std::endl; + << "}" << std::endl; } -void EmitResult(const std::string& result) +void EmitRunResult(const std::string& result) { - std::cout << "{\"event\": \"result\", \"data\": {" + std::cout << "{\"type\": \"result\", " + << "\"status\": \"success\", " + << "\"data\": {" << "\"result\": \"" << result << "\"" - << "}}" << std::endl; + << "}}" + << "}" << std::endl; } -void EmitResultWithFields(const std::string& version, const std::string& buildTime) +void EmitVersionResult(const std::string& version, const std::string& buildTime) { - std::cout << "{\"event\": \"result\", \"data\": {" + std::cout << "{\"type\": \"result\", " + << "\"status\": \"success\", " + << "\"data\": {" << "\"version\": \"" << version << "\", " << "\"build_time\": \"" << buildTime << "\"" - << "}}" << std::endl; + << "}}" + << "}" << std::endl; +} + +void EmitError(const std::string& errCode, const std::string& errMsg, const std::string& suggestion) +{ + std::cout << "{\"type\": \"result\", " + << "\"status\": \"failed\", " + << "\"errCode\": \"" << errCode << "\", " + << "\"errMsg\": \"" << errMsg << "\", " + << "\"suggestion\": \"" << suggestion << "\"" + << "}" << std::endl; } int RunCommand(const std::vector& args) @@ -63,7 +79,7 @@ int RunCommand(const std::vector& args) } EmitProgress(PROGRESS_MAX, "completed"); - EmitResult(result); + EmitRunResult(result); return 0; } @@ -74,7 +90,7 @@ int VersionCommand() const char* buildTime = "2026-04-04 00:00:00"; - EmitResultWithFields(version, buildTime); + EmitVersionResult(version, buildTime); return 0; } diff --git a/tools/ohos-simple/config.json b/tools/ohos-simple/config.json index 56771f8225..b42711bfd9 100644 --- a/tools/ohos-simple/config.json +++ b/tools/ohos-simple/config.json @@ -3,30 +3,7 @@ "version": "1.0.0", "description": "Simple CLI tool, supports message output, repeat count and verbose mode", "executablePath": "/system/bin/cli_tool/executable/ohos-simple", - "timeout": 30, "requirePermissions": [], - "eventTypes": ["result"], - "eventSchemas": { - "result": { - "type": "object", - "description": "Execution result event", - "properties": { - "status": { - "type": "string", - "description": "Execution status" - }, - "message": { - "type": "string", - "description": "Processed output message" - }, - "repeat_count": { - "type": "integer", - "description": "Actual repeat count" - } - }, - "required": ["status", "message", "repeat_count"] - } - }, "inputSchema": { "type": "object", "description": "Tool input parameters", @@ -69,16 +46,5 @@ } }, "required": ["status", "message", "repeat_count"] - }, - "argMapping": { - "type": "flag", - "templates": { - "message": "--message={value}", - "count": "--count={value}", - "verbose": { - "if_true": "--verbose", - "if_false": "" - } - } } } diff --git a/tools/ohos-simple/src/main.cpp b/tools/ohos-simple/src/main.cpp index 12bac58ef4..73518a5997 100644 --- a/tools/ohos-simple/src/main.cpp +++ b/tools/ohos-simple/src/main.cpp @@ -25,11 +25,24 @@ namespace { void EmitResult(const std::string& status, const std::string& message, int repeatCount) { - std::cout << "{\"event\": \"result\", \"data\": {" + std::cout << "{\"type\": \"result\", " + << "\"status\": \"" << status << "\", " + << "\"data\": {" << "\"status\": \"" << status << "\", " << "\"message\": \"" << message << "\", " << "\"repeat_count\": " << repeatCount - << "}}" << std::endl; + << "}}" + << "}" << std::endl; +} + +void EmitError(const std::string& errCode, const std::string& errMsg, const std::string& suggestion) +{ + std::cout << "{\"type\": \"result\", " + << "\"status\": \"failed\", " + << "\"errCode\": \"" << errCode << "\", " + << "\"errMsg\": \"" << errMsg << "\", " + << "\"suggestion\": \"" << suggestion << "\"" + << "}" << std::endl; } void ShowHelp() diff --git a/tools/ohos-timer/config.json b/tools/ohos-timer/config.json index 5e813b8ac3..1707a64710 100644 --- a/tools/ohos-timer/config.json +++ b/tools/ohos-timer/config.json @@ -3,7 +3,6 @@ "version": "1.0.0", "description": "Timer tool example, supports progress event output", "executablePath": "/system/bin/cli_tool/executable/ohos-timer", - "timeout": 30, "requirePermissions": [], "eventTypes": ["progress"], "inputSchema": { @@ -58,6 +57,9 @@ "type": "object", "description": "Progress event", "properties": { + "type": { + "const": "progress" + }, "percentage": { "type": "integer", "minimum": 0, @@ -71,20 +73,5 @@ }, "required": ["percentage", "status"] } - }, - "argMapping": { - "type": "flag", - "templates": { - "duration": "--duration={value}", - "interval": "--interval={value}", - "showProgress": { - "if_true": "--progress", - "if_false": "" - }, - "verbose": { - "if_true": "--verbose", - "if_false": "" - } - } } } diff --git a/tools/ohos-timer/src/main.cpp b/tools/ohos-timer/src/main.cpp index 8a421093d5..ebcc894da8 100644 --- a/tools/ohos-timer/src/main.cpp +++ b/tools/ohos-timer/src/main.cpp @@ -41,19 +41,32 @@ struct TimerConfig { void EmitProgress(int percentage, const std::string& status) { - std::cout << "{\"event\": \"progress\", \"data\": {" + std::cout << "{\"type\": \"progress\", " << "\"percentage\": " << percentage << ", " << "\"status\": \"" << status << "\"" - << "}}" << std::endl; + << "}" << std::endl; } void EmitResult(const std::string& status, int duration, int actualDuration) { - std::cout << "{\"event\": \"result\", \"data\": {" + std::cout << "{\"type\": \"result\", " + << "\"status\": \"" << status << "\", " + << "\"data\": {" << "\"status\": \"" << status << "\", " << "\"duration\": " << duration << ", " << "\"actual_duration\": " << actualDuration - << "}}" << std::endl; + << "}}" + << "}" << std::endl; +} + +void EmitError(const std::string& errCode, const std::string& errMsg, const std::string& suggestion) +{ + std::cout << "{\"type\": \"result\", " + << "\"status\": \"failed\", " + << "\"errCode\": \"" << errCode << "\", " + << "\"errMsg\": \"" << errMsg << "\", " + << "\"suggestion\": \"" << suggestion << "\"" + << "}" << std::endl; } void ShowHelp()