mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
do not parse empty default values and improve error messages
This commit is contained in:
parent
9c3f95782d
commit
08dd126f08
@ -618,7 +618,7 @@ For the described keys:
|
|||||||
# Bad call
|
# Bad call
|
||||||
$ ./app -fps=aaa
|
$ ./app -fps=aaa
|
||||||
ERRORS:
|
ERRORS:
|
||||||
Exception: can not convert: [aaa] to [double]
|
Parameter 'fps': can not convert: [aaa] to [double]
|
||||||
@endcode
|
@endcode
|
||||||
*/
|
*/
|
||||||
class CV_EXPORTS CommandLineParser
|
class CV_EXPORTS CommandLineParser
|
||||||
|
@ -97,23 +97,28 @@ void CommandLineParser::getByName(const String& name, bool space_delete, int typ
|
|||||||
{
|
{
|
||||||
for (size_t j = 0; j < impl->data[i].keys.size(); j++)
|
for (size_t j = 0; j < impl->data[i].keys.size(); j++)
|
||||||
{
|
{
|
||||||
if (name.compare(impl->data[i].keys[j]) == 0)
|
if (name == impl->data[i].keys[j])
|
||||||
{
|
{
|
||||||
String v = impl->data[i].def_value;
|
String v = impl->data[i].def_value;
|
||||||
if (space_delete)
|
if (space_delete)
|
||||||
v = impl->cat_string(v);
|
v = impl->cat_string(v);
|
||||||
|
|
||||||
|
// it is an error if we just got the default value here
|
||||||
|
if(v.empty())
|
||||||
|
break;
|
||||||
|
|
||||||
from_str(v, type, dst);
|
from_str(v, type, dst);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl->error = true;
|
impl->error = true;
|
||||||
impl->error_message = impl->error_message + "Unknown parameter " + name + "\n";
|
impl->error_message = impl->error_message + "Missing parameter: '" + name + "'\n";
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (Exception& e)
|
||||||
{
|
{
|
||||||
impl->error = true;
|
impl->error = true;
|
||||||
impl->error_message = impl->error_message + "Exception: " + String(e.what()) + "\n";
|
impl->error_message = impl->error_message + "Parameter '"+ name + "': " + e.err + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,17 +133,22 @@ void CommandLineParser::getByIndex(int index, bool space_delete, int type, void*
|
|||||||
{
|
{
|
||||||
String v = impl->data[i].def_value;
|
String v = impl->data[i].def_value;
|
||||||
if (space_delete == true) v = impl->cat_string(v);
|
if (space_delete == true) v = impl->cat_string(v);
|
||||||
|
|
||||||
|
// it is an error if we just got the default value here
|
||||||
|
if(v.empty())
|
||||||
|
break;
|
||||||
|
|
||||||
from_str(v, type, dst);
|
from_str(v, type, dst);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl->error = true;
|
impl->error = true;
|
||||||
impl->error_message = impl->error_message + "Unknown parameter #" + format("%d", index) + "\n";
|
impl->error_message = impl->error_message + "Missing parameter #" + format("%d", index) + "\n";
|
||||||
}
|
}
|
||||||
catch(std::exception & e)
|
catch(Exception& e)
|
||||||
{
|
{
|
||||||
impl->error = true;
|
impl->error = true;
|
||||||
impl->error_message = impl->error_message + "Exception: " + String(e.what()) + "\n";
|
impl->error_message = impl->error_message + format("Parameter #%d: ", index) + e.err + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user