configuration: add 'ignore-config-errors' switch
This commit is contained in:
1
NEWS
1
NEWS
@@ -3,6 +3,7 @@ ncmpcpp-0.6.4 (2015-05-02)
|
|||||||
* Fix title of a pop-up which shows during adding selected items to the current playlist.
|
* Fix title of a pop-up which shows during adding selected items to the current playlist.
|
||||||
* Correctly deal with leading separator while parsing filenames in tag editor.
|
* Correctly deal with leading separator while parsing filenames in tag editor.
|
||||||
* Fix initial incorrect window size that was occuring in some cases.
|
* Fix initial incorrect window size that was occuring in some cases.
|
||||||
|
* Unknown and invalid configuration options can now be ignored using command line option 'ignore-config-errors'.
|
||||||
|
|
||||||
ncmpcpp-0.6.3 (2015-03-02)
|
ncmpcpp-0.6.3 (2015-03-02)
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ bool configure(int argc, char **argv)
|
|||||||
("host,h", po::value<std::string>()->default_value("localhost"), "connect to server at host")
|
("host,h", po::value<std::string>()->default_value("localhost"), "connect to server at host")
|
||||||
("port,p", po::value<int>()->default_value(6600), "connect to server at port")
|
("port,p", po::value<int>()->default_value(6600), "connect to server at port")
|
||||||
("config,c", po::value<std::string>(&config_path)->default_value("~/.ncmpcpp/config"), "specify configuration file")
|
("config,c", po::value<std::string>(&config_path)->default_value("~/.ncmpcpp/config"), "specify configuration file")
|
||||||
|
("ignore-config-errors", po::value<bool>()->default_value(false), "ignore unknown and invalid options in configuration file")
|
||||||
("bindings,b", po::value<std::string>(&bindings_path)->default_value("~/.ncmpcpp/bindings"), "specify bindings file")
|
("bindings,b", po::value<std::string>(&bindings_path)->default_value("~/.ncmpcpp/bindings"), "specify bindings file")
|
||||||
("screen,s", po::value<std::string>(), "specify initial screen")
|
("screen,s", po::value<std::string>(), "specify initial screen")
|
||||||
("help,?", "show help message")
|
("help,?", "show help message")
|
||||||
@@ -130,7 +131,7 @@ bool configure(int argc, char **argv)
|
|||||||
|
|
||||||
// read configuration
|
// read configuration
|
||||||
expand_home(config_path);
|
expand_home(config_path);
|
||||||
if (Config.read(config_path) == false)
|
if (Config.read(config_path, vm["ignore-config-errors"].as<bool>()) == false)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
// if bindings file was not specified, use the one from main directory.
|
// if bindings file was not specified, use the one from main directory.
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ option_parser::worker buffer(NC::Buffer &arg, ValueT &&value, TransformT &&map)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Configuration::read(const std::string &config_path)
|
bool Configuration::read(const std::string &config_path, bool ignore_errors)
|
||||||
{
|
{
|
||||||
std::string mpd_host;
|
std::string mpd_host;
|
||||||
unsigned mpd_port;
|
unsigned mpd_port;
|
||||||
@@ -640,5 +640,5 @@ bool Configuration::read(const std::string &config_path)
|
|||||||
));
|
));
|
||||||
|
|
||||||
std::ifstream f(config_path);
|
std::ifstream f(config_path);
|
||||||
return p.run(f);
|
return p.run(f, ignore_errors);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ struct Configuration
|
|||||||
: playlist_disable_highlight_delay(0), visualizer_sync_interval(0)
|
: playlist_disable_highlight_delay(0), visualizer_sync_interval(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool read(const std::string &config_path);
|
bool read(const std::string &config_path, bool ignore_errors);
|
||||||
|
|
||||||
std::string ncmpcpp_directory;
|
std::string ncmpcpp_directory;
|
||||||
std::string lyrics_directory;
|
std::string lyrics_directory;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
#include "utility/option_parser.h"
|
#include "utility/option_parser.h"
|
||||||
|
|
||||||
bool option_parser::run(std::istream &is)
|
bool option_parser::run(std::istream &is, bool ignore_errors)
|
||||||
{
|
{
|
||||||
// quoted value. leftmost and rightmost quotation marks are the delimiters.
|
// quoted value. leftmost and rightmost quotation marks are the delimiters.
|
||||||
boost::regex quoted("(\\w+)\\h*=\\h*\"(.*)\"[^\"]*");
|
boost::regex quoted("(\\w+)\\h*=\\h*\"(.*)\"[^\"]*");
|
||||||
@@ -56,13 +56,15 @@ bool option_parser::run(std::istream &is)
|
|||||||
it->second.parse(match[2]);
|
it->second.parse(match[2]);
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
std::cerr << "Error while processing option \"" << option << "\": " << e.what() << "\n";
|
std::cerr << "Error while processing option \"" << option << "\": " << e.what() << "\n";
|
||||||
return false;
|
if (!ignore_errors)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "Unknown option: " << option << "\n";
|
std::cerr << "Unknown option: " << option << "\n";
|
||||||
return false;
|
if (!ignore_errors)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,7 +76,8 @@ bool option_parser::run(std::istream &is)
|
|||||||
p.second.run_default();
|
p.second.run_default();
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
std::cerr << "Error while finalizing option \"" << p.first << "\": " << e.what() << "\n";
|
std::cerr << "Error while finalizing option \"" << p.first << "\": " << e.what() << "\n";
|
||||||
return false;
|
if (ignore_errors)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ struct option_parser
|
|||||||
m_parsers[option] = std::forward<WorkerT>(w);
|
m_parsers[option] = std::forward<WorkerT>(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool run(std::istream &is);
|
bool run(std::istream &is, bool ignore_errors);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, worker> m_parsers;
|
std::unordered_map<std::string, worker> m_parsers;
|
||||||
|
|||||||
Reference in New Issue
Block a user