Skip to content

Commit

Permalink
[cli] allow executing the factoryreset command when running sync co…
Browse files Browse the repository at this point in the history
…mmands

When running the sync command, such as `diag radio receive 10000`, the cli
doesn't allow running other commands before the sync command returns. Which
causes that the sync command may be blocked for a very long time and users
can't do anything to terminate the sync command. This will also cause the
test script to fail to run the second case after running first case fails.

This commit allows the cli to execute the `factoryreset` command when running
the sync command.
  • Loading branch information
zhanglongxia committed Jan 10, 2025
1 parent 5ddcb44 commit 3f2cc6f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,15 @@ template <> otError Interpreter::Process<Cmd("reset")>(Arg aArgs[])

void Interpreter::ProcessLine(char *aLine)
{
Arg args[kMaxArgs + 1];
otError error = OT_ERROR_PARSE;
bool shouldOutputResult = true;
static const char kCmdFactoryReset[] = "factoryreset";
Arg args[kMaxArgs + 1];
otError error = OT_ERROR_PARSE;
bool shouldOutputResult = true;

OT_ASSERT(aLine != nullptr);

args[0].Clear();

// Validate and parse the input command line. The `error` is
// checked later after other conditions are handled.

Expand All @@ -317,7 +320,7 @@ void Interpreter::ProcessLine(char *aLine)
ExitNow();
}

if (mCommandIsPending)
if (mCommandIsPending && (args[0] != kCmdFactoryReset))
{
// If a previous command is still pending, ignore the new
// command (even if there is a parse error). We do not
Expand Down Expand Up @@ -347,7 +350,7 @@ void Interpreter::ProcessLine(char *aLine)
LogInput(args);

#if OPENTHREAD_CONFIG_DIAG_ENABLE
if (otDiagIsEnabled(GetInstancePtr()) && (args[0] != "diag") && (args[0] != "factoryreset"))
if (otDiagIsEnabled(GetInstancePtr()) && (args[0] != "diag") && (args[0] != kCmdFactoryReset))
{
OutputLine("under diagnostics mode, execute 'diag stop' before running any other commands.");
ExitNow(error = OT_ERROR_INVALID_STATE);
Expand Down

0 comments on commit 3f2cc6f

Please sign in to comment.