Skip to content

Commit

Permalink
[chip-tool] Make sure the multiple arguments separator for multiple w…
Browse files Browse the repository at this point in the history
…rite onto a single transation does not collide with the comma separator from the argument value itself
  • Loading branch information
vivien-apple committed Jul 7, 2022
1 parent 126f6b2 commit a87f26d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions examples/chip-tool/commands/common/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool Command::InitArguments(int argc, char ** argv)
}
}

VerifyOrExit((size_t)(argc) >= mandatoryArgsCount && (argvExtraArgsCount == 0 || (argvExtraArgsCount && optionalArgsCount)),
VerifyOrExit((size_t) (argc) >= mandatoryArgsCount && (argvExtraArgsCount == 0 || (argvExtraArgsCount && optionalArgsCount)),
ChipLogError(chipTool, "InitArgs: Wrong arguments number: %d instead of %u", argc,
static_cast<unsigned int>(mandatoryArgsCount)));

Expand Down Expand Up @@ -312,7 +312,11 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
while (ss.good())
{
std::string valueAsString;
getline(ss, valueAsString, ',');
// By default the parameter separator is ";" in order to not collapse with the argument itself if it contains commas
// (e.g a struct argument with multiple fields). In case one needs to use ";" it can be overriden with the following
// environment variable.
constexpr const char * kSeparatorVariable = "CHIPTOOL_CUSTOM_ARGUMENTS_SEPARATOR";
getline(ss, valueAsString, getenv(kSeparatorVariable) ? getenv(kSeparatorVariable)[0] : ';');

CustomArgument * customArgument = new CustomArgument();
vectorArgument->push_back(customArgument);
Expand Down

0 comments on commit a87f26d

Please sign in to comment.