Skip to content

Commit 5919793

Browse files
turonpull[bot]
authored andcommitted
[shell] Add subcommand help to shell config command. (#11764)
1 parent 52a4daf commit 5919793

File tree

1 file changed

+58
-36
lines changed

1 file changed

+58
-36
lines changed

src/lib/shell/commands/Config.cpp

+58-36
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ using chip::DeviceLayer::ConfigurationMgr;
3030
namespace chip {
3131
namespace Shell {
3232

33+
static chip::Shell::Engine sShellConfigSubcommands;
34+
35+
CHIP_ERROR ConfigHelpHandler(int argc, char ** argv)
36+
{
37+
sShellConfigSubcommands.ForEachCommand(PrintCommandHelp, nullptr);
38+
return CHIP_NO_ERROR;
39+
}
40+
3341
static CHIP_ERROR ConfigGetVendorId(bool printHeader)
3442
{
3543
streamer_t * sout = streamer_get();
@@ -44,6 +52,11 @@ static CHIP_ERROR ConfigGetVendorId(bool printHeader)
4452
return CHIP_NO_ERROR;
4553
}
4654

55+
static CHIP_ERROR ConfigVendorId(int argc, char ** argv)
56+
{
57+
return ConfigGetVendorId(false);
58+
}
59+
4760
static CHIP_ERROR ConfigGetProductId(bool printHeader)
4861
{
4962
streamer_t * sout = streamer_get();
@@ -58,6 +71,11 @@ static CHIP_ERROR ConfigGetProductId(bool printHeader)
5871
return CHIP_NO_ERROR;
5972
}
6073

74+
static CHIP_ERROR ConfigProductId(int argc, char ** argv)
75+
{
76+
return ConfigGetProductId(false);
77+
}
78+
6179
static CHIP_ERROR ConfigGetProductRevision(bool printHeader)
6280
{
6381
streamer_t * sout = streamer_get();
@@ -72,6 +90,11 @@ static CHIP_ERROR ConfigGetProductRevision(bool printHeader)
7290
return CHIP_NO_ERROR;
7391
}
7492

93+
static CHIP_ERROR ConfigProductRevision(int argc, char ** argv)
94+
{
95+
return ConfigGetProductRevision(false);
96+
}
97+
7598
static CHIP_ERROR ConfigGetSetupPinCode(bool printHeader)
7699
{
77100
streamer_t * sout = streamer_get();
@@ -86,6 +109,11 @@ static CHIP_ERROR ConfigGetSetupPinCode(bool printHeader)
86109
return CHIP_NO_ERROR;
87110
}
88111

112+
static CHIP_ERROR ConfigPinCode(int argc, char ** argv)
113+
{
114+
return ConfigGetSetupPinCode(false);
115+
}
116+
89117
static CHIP_ERROR ConfigGetSetupDiscriminator(bool printHeader)
90118
{
91119
streamer_t * sout = streamer_get();
@@ -122,6 +150,18 @@ static CHIP_ERROR ConfigSetSetupDiscriminator(char * argv)
122150
return error;
123151
}
124152

153+
static CHIP_ERROR ConfigDiscriminator(int argc, char ** argv)
154+
{
155+
if (argc == 0)
156+
{
157+
return ConfigGetSetupDiscriminator(false);
158+
}
159+
else
160+
{
161+
return ConfigSetSetupDiscriminator(argv[0]);
162+
}
163+
}
164+
125165
static CHIP_ERROR PrintAllConfigs()
126166
{
127167
ReturnErrorOnFailure(ConfigGetVendorId(true));
@@ -141,53 +181,35 @@ static CHIP_ERROR ConfigHandler(int argc, char ** argv)
141181
case 0:
142182
return PrintAllConfigs();
143183
case 1:
144-
if (strcmp(argv[0], "vendorid") == 0)
145-
{
146-
return ConfigGetVendorId(false);
147-
}
148-
else if (strcmp(argv[0], "productid") == 0)
149-
{
150-
return ConfigGetProductId(false);
151-
}
152-
else if (strcmp(argv[0], "productrev") == 0)
153-
{
154-
return ConfigGetProductRevision(false);
155-
}
156-
else if (strcmp(argv[0], "pincode") == 0)
184+
if ((strcmp(argv[0], "help") == 0) || (strcmp(argv[0], "-h") == 0))
157185
{
158-
return ConfigGetSetupPinCode(false);
186+
return ConfigHelpHandler(argc, argv);
159187
}
160-
else if (strcmp(argv[0], "discriminator") == 0)
161-
{
162-
return ConfigGetSetupDiscriminator(false);
163-
}
164-
else
165-
{
166-
return CHIP_ERROR_INVALID_ARGUMENT;
167-
}
168-
case 2:
169-
if (strcmp(argv[0], "discriminator") == 0)
170-
{
171-
return ConfigSetSetupDiscriminator(argv[1]);
172-
}
173-
else
174-
{
175-
return CHIP_ERROR_INVALID_ARGUMENT;
176-
}
177-
default:
178-
return CHIP_ERROR_INVALID_ARGUMENT;
179188
}
189+
return sShellConfigSubcommands.ExecCommand(argc, argv);
180190
}
181191

182192
void RegisterConfigCommands()
183193
{
184194

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

189-
// Register the root `device` command with the top-level shell.
190-
Engine::Root().RegisterCommands(&sDeviceComand, 1);
199+
static const shell_command_t sConfigSubCommands[] = {
200+
{ &ConfigHelpHandler, "help", "Usage: config <subcommand>" },
201+
{ &ConfigVendorId, "vendorid", "Get VendorId. Usage: config vendorid" },
202+
{ &ConfigProductId, "productid", "Get ProductId. Usage: config productid" },
203+
{ &ConfigProductRevision, "productrev", "Get ProductRevision. Usage: config preductrev" },
204+
{ &ConfigPinCode, "pincode", "Get commissioning pincode. Usage: config pincode" },
205+
{ &ConfigDiscriminator, "discriminator", "Get/Set commissioning discriminator. Usage: config discriminator [value]" },
206+
};
207+
208+
// Register `config` subcommands with the local shell dispatcher.
209+
sShellConfigSubcommands.RegisterCommands(sConfigSubCommands, ArraySize(sConfigSubCommands));
210+
211+
// Register the root `config` command with the top-level shell.
212+
Engine::Root().RegisterCommands(&sConfigComand, 1);
191213
return;
192214
}
193215

0 commit comments

Comments
 (0)