mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
Co-Authored-By: Agent
Signed-off-by: duansizhao <duansizhao@huawei.com> Change-Id: I5eb8f28e5a2f7acc6256de6350b88456b1d8c46a
This commit is contained in:
@@ -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}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<std::string>& args)
|
||||
@@ -63,7 +79,7 @@ int RunCommand(const std::vector<std::string>& 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;
|
||||
}
|
||||
|
||||
@@ -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": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user