@@ -3178,9 +3178,13 @@ GDALAlgorithm::AddOpenOptionsArg(std::vector<std::string> *pValue,
31783178 auto &arg = AddArg (GDAL_ARG_NAME_OPEN_OPTION, 0 ,
31793179 MsgOrDefault (helpMessage, _ (" Open options" )), pValue)
31803180 .AddAlias (" oo" )
3181- .SetMetaVar (" KEY=VALUE" )
3181+ .SetMetaVar (" <KEY>=<VALUE>" )
3182+ .SetPackedValuesAllowed (false )
31823183 .SetCategory (GAAC_ADVANCED);
31833184
3185+ arg.AddValidationAction ([this , &arg]()
3186+ { return ParseAndValidateKeyValue (arg); });
3187+
31843188 arg.SetAutoCompleteFunction (
31853189 [this ](const std::string ¤tValue)
31863190 {
@@ -3692,10 +3696,10 @@ GDALAlgorithm::AddBandArg(std::vector<int> *pValue, const char *helpMessage)
36923696}
36933697
36943698/* ***********************************************************************/
3695- /* ValidateKeyValue() */
3699+ /* ParseAndValidateKeyValue() */
36963700/* ***********************************************************************/
36973701
3698- bool GDALAlgorithm::ValidateKeyValue ( const GDALAlgorithmArg &arg) const
3702+ bool GDALAlgorithm::ParseAndValidateKeyValue ( GDALAlgorithmArg &arg)
36993703{
37003704 const auto Validate = [this , &arg](const std::string &val)
37013705 {
@@ -3717,7 +3721,60 @@ bool GDALAlgorithm::ValidateKeyValue(const GDALAlgorithmArg &arg) const
37173721 }
37183722 else if (arg.GetType () == GAAT_STRING_LIST)
37193723 {
3720- for (const auto &val : arg.Get <std::vector<std::string>>())
3724+ std::vector<std::string> &vals = arg.Get <std::vector<std::string>>();
3725+ if (vals.size () == 1 )
3726+ {
3727+ // Try to split A=B,C=D into A=B and C=D if there is no ambiguity
3728+ std::vector<std::string> newVals;
3729+ std::string curToken;
3730+ bool canSplitOnComma = true ;
3731+ char lastSep = 0 ;
3732+ bool inString = false ;
3733+ bool equalFoundInLastToken = false ;
3734+ for (char c : vals[0 ])
3735+ {
3736+ if (!inString && c == ' ,' )
3737+ {
3738+ if (lastSep != ' =' || !equalFoundInLastToken)
3739+ {
3740+ canSplitOnComma = false ;
3741+ break ;
3742+ }
3743+ lastSep = c;
3744+ newVals.push_back (curToken);
3745+ curToken.clear ();
3746+ equalFoundInLastToken = false ;
3747+ }
3748+ else if (!inString && c == ' =' )
3749+ {
3750+ if (lastSep == ' =' )
3751+ {
3752+ canSplitOnComma = false ;
3753+ break ;
3754+ }
3755+ equalFoundInLastToken = true ;
3756+ lastSep = c;
3757+ curToken += c;
3758+ }
3759+ else if (c == ' "' )
3760+ {
3761+ inString = !inString;
3762+ curToken += c;
3763+ }
3764+ else
3765+ {
3766+ curToken += c;
3767+ }
3768+ }
3769+ if (canSplitOnComma && !inString && equalFoundInLastToken)
3770+ {
3771+ if (!curToken.empty ())
3772+ newVals.emplace_back (std::move (curToken));
3773+ vals = std::move (newVals);
3774+ }
3775+ }
3776+
3777+ for (const auto &val : vals)
37213778 {
37223779 if (!Validate (val))
37233780 return false ;
@@ -3845,8 +3902,10 @@ GDALAlgorithm::AddCreationOptionsArg(std::vector<std::string> *pValue,
38453902 auto &arg = AddArg (" creation-option" , 0 ,
38463903 MsgOrDefault (helpMessage, _ (" Creation option" )), pValue)
38473904 .AddAlias (" co" )
3848- .SetMetaVar (" <KEY>=<VALUE>" );
3849- arg.AddValidationAction ([this , &arg]() { return ValidateKeyValue (arg); });
3905+ .SetMetaVar (" <KEY>=<VALUE>" )
3906+ .SetPackedValuesAllowed (false );
3907+ arg.AddValidationAction ([this , &arg]()
3908+ { return ParseAndValidateKeyValue (arg); });
38503909
38513910 arg.SetAutoCompleteFunction (
38523911 [this ](const std::string ¤tValue)
@@ -3945,8 +4004,10 @@ GDALAlgorithm::AddLayerCreationOptionsArg(std::vector<std::string> *pValue,
39454004 AddArg (" layer-creation-option" , 0 ,
39464005 MsgOrDefault (helpMessage, _ (" Layer creation option" )), pValue)
39474006 .AddAlias (" lco" )
3948- .SetMetaVar (" <KEY>=<VALUE>" );
3949- arg.AddValidationAction ([this , &arg]() { return ValidateKeyValue (arg); });
4007+ .SetMetaVar (" <KEY>=<VALUE>" )
4008+ .SetPackedValuesAllowed (false );
4009+ arg.AddValidationAction ([this , &arg]()
4010+ { return ParseAndValidateKeyValue (arg); });
39504011
39514012 arg.SetAutoCompleteFunction (
39524013 [this ](const std::string ¤tValue)
0 commit comments