test/run_input: add option to load a configuration file
This commit is contained in:
parent
7d5b859756
commit
6c239f7a00
|
@ -26,9 +26,11 @@
|
||||||
#include "event/Thread.hxx"
|
#include "event/Thread.hxx"
|
||||||
#include "thread/Cond.hxx"
|
#include "thread/Cond.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
#include "fs/Path.hxx"
|
||||||
#include "fs/io/BufferedOutputStream.hxx"
|
#include "fs/io/BufferedOutputStream.hxx"
|
||||||
#include "fs/io/StdioOutputStream.hxx"
|
#include "fs/io/StdioOutputStream.hxx"
|
||||||
#include "util/ConstBuffer.hxx"
|
#include "util/ConstBuffer.hxx"
|
||||||
|
#include "util/OptionDef.hxx"
|
||||||
#include "util/OptionParser.hxx"
|
#include "util/OptionParser.hxx"
|
||||||
|
|
||||||
#ifdef ENABLE_ARCHIVE
|
#ifdef ENABLE_ARCHIVE
|
||||||
|
@ -42,6 +44,16 @@
|
||||||
|
|
||||||
struct CommandLine {
|
struct CommandLine {
|
||||||
const char *uri = nullptr;
|
const char *uri = nullptr;
|
||||||
|
|
||||||
|
Path config_path = Path::Null();
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Option {
|
||||||
|
OPTION_CONFIG,
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr OptionDef option_defs[] = {
|
||||||
|
{"config", 0, true, "Load a MPD configuration file"},
|
||||||
};
|
};
|
||||||
|
|
||||||
static CommandLine
|
static CommandLine
|
||||||
|
@ -49,13 +61,18 @@ ParseCommandLine(int argc, char **argv)
|
||||||
{
|
{
|
||||||
CommandLine c;
|
CommandLine c;
|
||||||
|
|
||||||
OptionParser option_parser(nullptr, argc, argv);
|
OptionParser option_parser(option_defs, argc, argv);
|
||||||
while (auto o = option_parser.Next()) {
|
while (auto o = option_parser.Next()) {
|
||||||
|
switch (Option(o.index)) {
|
||||||
|
case OPTION_CONFIG:
|
||||||
|
c.config_path = Path::FromFS(o.value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto args = option_parser.GetRemaining();
|
auto args = option_parser.GetRemaining();
|
||||||
if (args.size != 1)
|
if (args.size != 1)
|
||||||
throw std::runtime_error("Usage: run_input URI");
|
throw std::runtime_error("Usage: run_input [--config=FILE] URI");
|
||||||
|
|
||||||
c.uri = args.front();
|
c.uri = args.front();
|
||||||
return c;
|
return c;
|
||||||
|
@ -65,9 +82,13 @@ class GlobalInit {
|
||||||
EventThread io_thread;
|
EventThread io_thread;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GlobalInit() {
|
GlobalInit(Path config_path) {
|
||||||
io_thread.Start();
|
io_thread.Start();
|
||||||
config_global_init();
|
config_global_init();
|
||||||
|
|
||||||
|
if (!config_path.IsNull())
|
||||||
|
ReadConfigFile(config_path);
|
||||||
|
|
||||||
#ifdef ENABLE_ARCHIVE
|
#ifdef ENABLE_ARCHIVE
|
||||||
archive_plugin_init_all();
|
archive_plugin_init_all();
|
||||||
#endif
|
#endif
|
||||||
|
@ -134,7 +155,7 @@ try {
|
||||||
|
|
||||||
/* initialize MPD */
|
/* initialize MPD */
|
||||||
|
|
||||||
const GlobalInit init;
|
const GlobalInit init(c.config_path);
|
||||||
|
|
||||||
/* open the stream and dump it */
|
/* open the stream and dump it */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue