Add '--quiet' comand line option to suppress some output
This commit is contained in:
committed by
Andrzej Rybczak
parent
5b7ea189ce
commit
7ba2c3534c
1
NEWS
1
NEWS
@@ -27,6 +27,7 @@ ncmpcpp-0.8 (????-??-??)
|
||||
* Seek immediately after invoking appropriate action once.
|
||||
* Added support for locating current song in playlist editor.
|
||||
* Disable autocenter mode while searching and filtering.
|
||||
* Added '--quiet' comand line argument that supresses messages shown at startup.
|
||||
|
||||
ncmpcpp-0.7.7 (2016-10-31)
|
||||
* Fixed compilation on 32bit platforms.
|
||||
|
||||
@@ -33,6 +33,9 @@ Specify the startup screen (<name> may be: help, playlist, browser, search_engin
|
||||
.B \-S, \-\-slave-screen <name>
|
||||
Specify the startup slave screen (<name> may be: help, playlist, browser, search_engine, media_library, playlist_editor, tag_editor, outputs, visualizer, clock)
|
||||
.TP
|
||||
.B \-q, \-\-quiet
|
||||
Suppress logs and excess output
|
||||
.TP
|
||||
.B \-?, \-\-help
|
||||
Display help.
|
||||
.TP
|
||||
|
||||
@@ -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