diff --git a/src/cli/README.md b/src/cli/README.md index 345e09116..74c93f417 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -1859,6 +1859,16 @@ OPENTHREAD/gf4f2f04; Jul 1 2016 17:00:09 Done ``` +### version api + +Print API version number. + +```bash +> version api +28 +Done +``` + ### mac retries direct Get the number of direct TX retries on the MAC layer. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index b9f4faef8..79392d2e3 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -3685,13 +3685,25 @@ exit: otError Interpreter::ProcessVersion(uint8_t aArgsLength, char *aArgs[]) { - OT_UNUSED_VARIABLE(aArgsLength); - OT_UNUSED_VARIABLE(aArgs); + otError error = OT_ERROR_NONE; - const char *version = otGetVersionString(); - OutputLine("%s", static_cast(version)); + if (aArgsLength == 0) + { + OutputLine("%s", otGetVersionString()); + ExitNow(); + } - return OT_ERROR_NONE; + if (strcmp(aArgs[0], "api") == 0) + { + OutputLine("%d", OPENTHREAD_API_VERSION); + } + else + { + ExitNow(error = OT_ERROR_INVALID_COMMAND); + } + +exit: + return error; } #if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD diff --git a/tests/scripts/expect/cli-misc.exp b/tests/scripts/expect/cli-misc.exp index 2b21efeb1..6b49fa8e6 100755 --- a/tests/scripts/expect/cli-misc.exp +++ b/tests/scripts/expect/cli-misc.exp @@ -108,6 +108,11 @@ expect "Done" send "version\n" expect "Done" +send "version api\n" +expect -re {\d+} +expect "Done" +send "version something_invalid\n" +expect "Error 35: InvalidCommand" send "joinerport 10001\n" expect "Done"