Commit 7d5b8597 authored by Max Kellermann's avatar Max Kellermann

test/run_input: add command-line option parser

parent 3e2e0d06
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include "Log.hxx" #include "Log.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/OptionParser.hxx"
#ifdef ENABLE_ARCHIVE #ifdef ENABLE_ARCHIVE
#include "archive/ArchiveList.hxx" #include "archive/ArchiveList.hxx"
...@@ -38,6 +40,27 @@ ...@@ -38,6 +40,27 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
struct CommandLine {
const char *uri = nullptr;
};
static CommandLine
ParseCommandLine(int argc, char **argv)
{
CommandLine c;
OptionParser option_parser(nullptr, argc, argv);
while (auto o = option_parser.Next()) {
}
auto args = option_parser.GetRemaining();
if (args.size != 1)
throw std::runtime_error("Usage: run_input URI");
c.uri = args.front();
return c;
}
class GlobalInit { class GlobalInit {
EventThread io_thread; EventThread io_thread;
...@@ -107,10 +130,7 @@ dump_input_stream(InputStream *is) ...@@ -107,10 +130,7 @@ dump_input_stream(InputStream *is)
int main(int argc, char **argv) int main(int argc, char **argv)
try { try {
if (argc != 2) { const auto c = ParseCommandLine(argc, argv);
fprintf(stderr, "Usage: run_input URI\n");
return EXIT_FAILURE;
}
/* initialize MPD */ /* initialize MPD */
...@@ -120,7 +140,7 @@ try { ...@@ -120,7 +140,7 @@ try {
Mutex mutex; Mutex mutex;
Cond cond; Cond cond;
auto is = InputStream::OpenReady(argv[1], mutex, cond); auto is = InputStream::OpenReady(c.uri, mutex, cond);
return dump_input_stream(is.get()); return dump_input_stream(is.get());
} catch (const std::exception &e) { } catch (const std::exception &e) {
LogError(e); LogError(e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment