Add '--quiet' comand line option to suppress some output
This commit is contained in:
committed by
Andrzej Rybczak
parent
5b7ea189ce
commit
7ba2c3534c
@@ -24,6 +24,7 @@
|
||||
#include <boost/program_options.hpp>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "bindings.h"
|
||||
#include "configuration.h"
|
||||
@@ -88,6 +89,7 @@ bool configure(int argc, char **argv)
|
||||
("slave-screen,S", po::value<std::string>()->value_name("SCREEN"), "specify the startup slave screen")
|
||||
("help,?", "show help message")
|
||||
("version,v", "display version information")
|
||||
("quiet,q", "suppress logs and excess output")
|
||||
;
|
||||
|
||||
po::variables_map vm;
|
||||
@@ -95,6 +97,14 @@ bool configure(int argc, char **argv)
|
||||
{
|
||||
po::store(po::parse_command_line(argc, argv, options), vm);
|
||||
|
||||
// suppress messages from std::clog
|
||||
if (vm.count("quiet"))
|
||||
{
|
||||
std::ofstream null_stream;
|
||||
null_stream.open("/dev/null");
|
||||
std::clog.rdbuf(null_stream.rdbuf());
|
||||
}
|
||||
|
||||
if (vm.count("help"))
|
||||
{
|
||||
cout << "Usage: " << argv[0] << " [options]...\n" << options << "\n";
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace {
|
||||
|
||||
std::ofstream errorlog;
|
||||
std::streambuf *cerr_buffer;
|
||||
std::streambuf *clog_buffer;
|
||||
|
||||
volatile bool run_resize_screen = false;
|
||||
|
||||
@@ -69,8 +70,9 @@ void sighandler(int sig)
|
||||
|
||||
void do_at_exit()
|
||||
{
|
||||
// restore old cerr buffer
|
||||
// restore old cerr & clog buffers
|
||||
std::cerr.rdbuf(cerr_buffer);
|
||||
std::clog.rdbuf(clog_buffer);
|
||||
errorlog.close();
|
||||
Mpd.Disconnect();
|
||||
NC::destroyScreen();
|
||||
@@ -92,6 +94,9 @@ int main(int argc, char **argv)
|
||||
std::setlocale(LC_ALL, "");
|
||||
std::locale::global(Charset::internalLocale());
|
||||
|
||||
// clog might be overriden in configure, so preserve the original buffer.
|
||||
clog_buffer = std::clog.rdbuf();
|
||||
|
||||
if (!configure(argc, argv))
|
||||
return 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user