[libcalamares] Complain if key isn't set

- Previous check would also fail when the setting is false,
   not just when the key is missing.
This commit is contained in:
Adriaan de Groot 2018-06-19 17:58:26 +02:00
parent 1a097f8c49
commit b283ad69d5

View file

@ -29,13 +29,19 @@
#include <yaml-cpp/yaml.h>
static bool
hasValue( const YAML::Node& v )
{
return !( ( v.Type() == YAML::NodeType::Null ) || ( v.Type() == YAML::NodeType::Undefined ) );
}
/** Helper function to grab a QString out of the config, and to warn if not present. */
static QString
requireString( const YAML::Node& config, const char* key )
{
if ( config[ key ] )
return QString::fromStdString( config[ key ].as< std::string >() );
auto v = config[ key ];
if ( hasValue(v) )
return QString::fromStdString( v.as< std::string >() );
else
{
cWarning() << "Required settings.conf key" << key << "is missing.";
@ -47,8 +53,9 @@ requireString( const YAML::Node& config, const char* key )
static bool
requireBool( const YAML::Node& config, const char* key, bool d )
{
if ( config[ key ] )
return config[ key ].as< bool >();
auto v = config[ key ];
if ( hasValue(v) )
return v.as< bool >();
else
{
cWarning() << "Required settings.conf key" << key << "is missing.";