test/run_output: use OptionParser, add option "--verbose"
This commit is contained in:
parent
b1a9958c66
commit
bc2988144e
@ -26,10 +26,13 @@
|
|||||||
#include "fs/NarrowPath.hxx"
|
#include "fs/NarrowPath.hxx"
|
||||||
#include "pcm/AudioParser.hxx"
|
#include "pcm/AudioParser.hxx"
|
||||||
#include "pcm/AudioFormat.hxx"
|
#include "pcm/AudioFormat.hxx"
|
||||||
|
#include "util/OptionDef.hxx"
|
||||||
|
#include "util/OptionParser.hxx"
|
||||||
#include "util/StringBuffer.hxx"
|
#include "util/StringBuffer.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
#include "util/ScopeExit.hxx"
|
#include "util/ScopeExit.hxx"
|
||||||
#include "util/PrintException.hxx"
|
#include "util/PrintException.hxx"
|
||||||
|
#include "LogBackend.hxx"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -45,6 +48,16 @@ struct CommandLine {
|
|||||||
const char *output_name = nullptr;
|
const char *output_name = nullptr;
|
||||||
|
|
||||||
AudioFormat audio_format{44100, SampleFormat::S16, 2};
|
AudioFormat audio_format{44100, SampleFormat::S16, 2};
|
||||||
|
|
||||||
|
bool verbose = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Option {
|
||||||
|
OPTION_VERBOSE,
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr OptionDef option_defs[] = {
|
||||||
|
{"verbose", 'v', false, "Verbose logging"},
|
||||||
};
|
};
|
||||||
|
|
||||||
static CommandLine
|
static CommandLine
|
||||||
@ -52,14 +65,24 @@ ParseCommandLine(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
CommandLine c;
|
CommandLine c;
|
||||||
|
|
||||||
if (argc < 3 || argc > 4)
|
OptionParser option_parser(option_defs, argc, argv);
|
||||||
|
while (auto o = option_parser.Next()) {
|
||||||
|
switch (Option(o.index)) {
|
||||||
|
case OPTION_VERBOSE:
|
||||||
|
c.verbose = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto args = option_parser.GetRemaining();
|
||||||
|
if (args.size < 2 || args.size > 3)
|
||||||
throw std::runtime_error("Usage: run_output CONFIG NAME [FORMAT] <IN");
|
throw std::runtime_error("Usage: run_output CONFIG NAME [FORMAT] <IN");
|
||||||
|
|
||||||
c.config_path = argv[1];
|
c.config_path = args[0];
|
||||||
c.output_name = argv[2];
|
c.output_name = args[1];
|
||||||
|
|
||||||
if (argc > 3)
|
if (args.size > 2)
|
||||||
c.audio_format = ParseAudioFormat(argv[3], false);
|
c.audio_format = ParseAudioFormat(args[2], false);
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@ -82,6 +105,8 @@ LoadAudioOutput(const ConfigData &config, EventLoop &event_loop,
|
|||||||
if (plugin == nullptr)
|
if (plugin == nullptr)
|
||||||
throw FormatRuntimeError("No such audio output plugin: %s",
|
throw FormatRuntimeError("No such audio output plugin: %s",
|
||||||
plugin_name);
|
plugin_name);
|
||||||
|
#include "util/OptionDef.hxx"
|
||||||
|
#include "util/OptionParser.hxx"
|
||||||
|
|
||||||
return std::unique_ptr<AudioOutput>(ao_plugin_init(event_loop, *plugin,
|
return std::unique_ptr<AudioOutput>(ao_plugin_init(event_loop, *plugin,
|
||||||
*block));
|
*block));
|
||||||
@ -133,6 +158,7 @@ run_output(AudioOutput &ao, AudioFormat audio_format)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
try {
|
try {
|
||||||
const auto c = ParseCommandLine(argc, argv);
|
const auto c = ParseCommandLine(argc, argv);
|
||||||
|
SetLogThreshold(c.verbose ? LogLevel::DEBUG : LogLevel::INFO);
|
||||||
|
|
||||||
/* read configuration file (mpd.conf) */
|
/* read configuration file (mpd.conf) */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user