mirror of
				https://github.com/aportelli/LatAnalyze.git
				synced 2025-11-04 08:04:32 +00:00 
			
		
		
		
	option parser checks for duplicated options
This commit is contained in:
		@@ -46,6 +46,33 @@ void OptParser::addOption(const std::string shortName,
 | 
				
			|||||||
    par.helpMessage = helpMessage;
 | 
					    par.helpMessage = helpMessage;
 | 
				
			||||||
    par.type        = type;
 | 
					    par.type        = type;
 | 
				
			||||||
    par.optional    = optional;
 | 
					    par.optional    = optional;
 | 
				
			||||||
 | 
					    auto it = std::find_if(opt_.begin(), opt_.end(), [&par](const OptPar & p)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        bool match = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        match |= (par.shortName == p.shortName) and !par.shortName.empty();
 | 
				
			||||||
 | 
					        match |= (par.longName == p.longName) and !par.longName.empty();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return match;
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    if (it != opt_.end())
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        string opt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!it->shortName.empty())
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            opt += "-" + it->shortName;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (!opt.empty())
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            opt += "/";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (!it->longName.empty())
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            opt += "--" + it->longName;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        throw(logic_error("duplicate option " + opt + " (in the code, not in the command line)"));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    opt_.push_back(par);
 | 
					    opt_.push_back(par);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user