Skip to content

Commit

Permalink
[shell] Add subcommand help to shell config command. (#11764)
Browse files Browse the repository at this point in the history
  • Loading branch information
turon authored and pull[bot] committed Dec 15, 2021
1 parent 440d60b commit 37050e1
Showing 1 changed file with 58 additions and 36 deletions.
94 changes: 58 additions & 36 deletions src/lib/shell/commands/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ using chip::DeviceLayer::ConfigurationMgr;
namespace chip {
namespace Shell {

static chip::Shell::Engine sShellConfigSubcommands;

CHIP_ERROR ConfigHelpHandler(int argc, char ** argv)
{
sShellConfigSubcommands.ForEachCommand(PrintCommandHelp, nullptr);
return CHIP_NO_ERROR;
}

static CHIP_ERROR ConfigGetVendorId(bool printHeader)
{
streamer_t * sout = streamer_get();
Expand All @@ -44,6 +52,11 @@ static CHIP_ERROR ConfigGetVendorId(bool printHeader)
return CHIP_NO_ERROR;
}

static CHIP_ERROR ConfigVendorId(int argc, char ** argv)
{
return ConfigGetVendorId(false);
}

static CHIP_ERROR ConfigGetProductId(bool printHeader)
{
streamer_t * sout = streamer_get();
Expand All @@ -58,6 +71,11 @@ static CHIP_ERROR ConfigGetProductId(bool printHeader)
return CHIP_NO_ERROR;
}

static CHIP_ERROR ConfigProductId(int argc, char ** argv)
{
return ConfigGetProductId(false);
}

static CHIP_ERROR ConfigGetProductRevision(bool printHeader)
{
streamer_t * sout = streamer_get();
Expand All @@ -72,6 +90,11 @@ static CHIP_ERROR ConfigGetProductRevision(bool printHeader)
return CHIP_NO_ERROR;
}

static CHIP_ERROR ConfigProductRevision(int argc, char ** argv)
{
return ConfigGetProductRevision(false);
}

static CHIP_ERROR ConfigGetSetupPinCode(bool printHeader)
{
streamer_t * sout = streamer_get();
Expand All @@ -86,6 +109,11 @@ static CHIP_ERROR ConfigGetSetupPinCode(bool printHeader)
return CHIP_NO_ERROR;
}

static CHIP_ERROR ConfigPinCode(int argc, char ** argv)
{
return ConfigGetSetupPinCode(false);
}

static CHIP_ERROR ConfigGetSetupDiscriminator(bool printHeader)
{
streamer_t * sout = streamer_get();
Expand Down Expand Up @@ -122,6 +150,18 @@ static CHIP_ERROR ConfigSetSetupDiscriminator(char * argv)
return error;
}

static CHIP_ERROR ConfigDiscriminator(int argc, char ** argv)
{
if (argc == 0)
{
return ConfigGetSetupDiscriminator(false);
}
else
{
return ConfigSetSetupDiscriminator(argv[0]);
}
}

static CHIP_ERROR PrintAllConfigs()
{
ReturnErrorOnFailure(ConfigGetVendorId(true));
Expand All @@ -141,53 +181,35 @@ static CHIP_ERROR ConfigHandler(int argc, char ** argv)
case 0:
return PrintAllConfigs();
case 1:
if (strcmp(argv[0], "vendorid") == 0)
{
return ConfigGetVendorId(false);
}
else if (strcmp(argv[0], "productid") == 0)
{
return ConfigGetProductId(false);
}
else if (strcmp(argv[0], "productrev") == 0)
{
return ConfigGetProductRevision(false);
}
else if (strcmp(argv[0], "pincode") == 0)
if ((strcmp(argv[0], "help") == 0) || (strcmp(argv[0], "-h") == 0))
{
return ConfigGetSetupPinCode(false);
return ConfigHelpHandler(argc, argv);
}
else if (strcmp(argv[0], "discriminator") == 0)
{
return ConfigGetSetupDiscriminator(false);
}
else
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
case 2:
if (strcmp(argv[0], "discriminator") == 0)
{
return ConfigSetSetupDiscriminator(argv[1]);
}
else
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
default:
return CHIP_ERROR_INVALID_ARGUMENT;
}
return sShellConfigSubcommands.ExecCommand(argc, argv);
}

void RegisterConfigCommands()
{

static const shell_command_t sDeviceComand = { &ConfigHandler, "config",
static const shell_command_t sConfigComand = { &ConfigHandler, "config",
"Manage device configuration. Usage to dump value: config [param_name] and "
"to set some values (discriminator): config [param_name] [param_value]." };

// Register the root `device` command with the top-level shell.
Engine::Root().RegisterCommands(&sDeviceComand, 1);
static const shell_command_t sConfigSubCommands[] = {
{ &ConfigHelpHandler, "help", "Usage: config <subcommand>" },
{ &ConfigVendorId, "vendorid", "Get VendorId. Usage: config vendorid" },
{ &ConfigProductId, "productid", "Get ProductId. Usage: config productid" },
{ &ConfigProductRevision, "productrev", "Get ProductRevision. Usage: config preductrev" },
{ &ConfigPinCode, "pincode", "Get commissioning pincode. Usage: config pincode" },
{ &ConfigDiscriminator, "discriminator", "Get/Set commissioning discriminator. Usage: config discriminator [value]" },
};

// Register `config` subcommands with the local shell dispatcher.
sShellConfigSubcommands.RegisterCommands(sConfigSubCommands, ArraySize(sConfigSubCommands));

// Register the root `config` command with the top-level shell.
Engine::Root().RegisterCommands(&sConfigComand, 1);
return;
}

Expand Down

0 comments on commit 37050e1

Please sign in to comment.