[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:
parent
1a097f8c49
commit
b283ad69d5
@ -29,13 +29,19 @@
|
|||||||
|
|
||||||
#include <yaml-cpp/yaml.h>
|
#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. */
|
/** Helper function to grab a QString out of the config, and to warn if not present. */
|
||||||
static QString
|
static QString
|
||||||
requireString( const YAML::Node& config, const char* key )
|
requireString( const YAML::Node& config, const char* key )
|
||||||
{
|
{
|
||||||
if ( config[ key ] )
|
auto v = config[ key ];
|
||||||
return QString::fromStdString( config[ key ].as< std::string >() );
|
if ( hasValue(v) )
|
||||||
|
return QString::fromStdString( v.as< std::string >() );
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cWarning() << "Required settings.conf key" << key << "is missing.";
|
cWarning() << "Required settings.conf key" << key << "is missing.";
|
||||||
@ -47,8 +53,9 @@ requireString( const YAML::Node& config, const char* key )
|
|||||||
static bool
|
static bool
|
||||||
requireBool( const YAML::Node& config, const char* key, bool d )
|
requireBool( const YAML::Node& config, const char* key, bool d )
|
||||||
{
|
{
|
||||||
if ( config[ key ] )
|
auto v = config[ key ];
|
||||||
return config[ key ].as< bool >();
|
if ( hasValue(v) )
|
||||||
|
return v.as< bool >();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cWarning() << "Required settings.conf key" << key << "is missing.";
|
cWarning() << "Required settings.conf key" << key << "is missing.";
|
||||||
|
Loading…
Reference in New Issue
Block a user