Add verbose option

Using the option -v (--verbose) all spawned commands are print
on the terminal. Note that this was done by default on previous
versions.
This commit is contained in:
Enrico Forestieri 2016-08-17 22:32:14 +02:00
parent 6e88c0062c
commit 2a371bb4b3
8 changed files with 46 additions and 1 deletions

View File

@ -94,6 +94,9 @@ by using the lyxpipe, ask an already running instance of LyX to open the
documents passed as arguments and then exit. If the lyxpipe is not set up or documents passed as arguments and then exit. If the lyxpipe is not set up or
is not working, a new instance is created and execution continues normally. is not working, a new instance is created and execution continues normally.
.TP .TP
\fB \-v [\-\-verbose]\fP
print on terminal all spawned external commands.
.TP
.BI \-batch .BI \-batch
causes LyX to run the given commands without opening a GUI window. causes LyX to run the given commands without opening a GUI window.
Thus, something like: Thus, something like:

View File

@ -92,6 +92,12 @@ namespace os = support::os;
bool use_gui = true; bool use_gui = true;
// Report on the terminal about spawned commands. The default is false
// and can be changed with the option -v (--verbose).
bool verbose = false;
// We default to open documents in an already running instance, provided that // We default to open documents in an already running instance, provided that
// the lyxpipe has been setup. This can be overridden either on the command // the lyxpipe has been setup. This can be overridden either on the command
// line or through preference settings. // line or through preference settings.
@ -1161,6 +1167,8 @@ int parse_help(string const &, string const &, string &)
"\t-r [--remote]\n" "\t-r [--remote]\n"
" open documents in an already running instance\n" " open documents in an already running instance\n"
" (a working lyxpipe is needed)\n" " (a working lyxpipe is needed)\n"
"\t-v [--verbose]\n"
" report on terminal about spawned commands.\n"
"\t-batch execute commands without launching GUI and exit.\n" "\t-batch execute commands without launching GUI and exit.\n"
"\t-version summarize version and build info\n" "\t-version summarize version and build info\n"
"Check the LyX man page for more details.")) << endl; "Check the LyX man page for more details.")) << endl;
@ -1295,6 +1303,13 @@ int parse_remote(string const &, string const &, string &)
} }
int parse_verbose(string const &, string const &, string &)
{
verbose = true;
return 0;
}
int parse_force(string const & arg, string const &, string &) int parse_force(string const & arg, string const &, string &)
{ {
if (arg == "all") { if (arg == "all") {
@ -1342,6 +1357,8 @@ void LyX::easyParse(int & argc, char * argv[])
cmdmap["--no-remote"] = parse_noremote; cmdmap["--no-remote"] = parse_noremote;
cmdmap["-r"] = parse_remote; cmdmap["-r"] = parse_remote;
cmdmap["--remote"] = parse_remote; cmdmap["--remote"] = parse_remote;
cmdmap["-v"] = parse_verbose;
cmdmap["--verbose"] = parse_verbose;
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
map<string, cmd_helper>::const_iterator it map<string, cmd_helper>::const_iterator it

View File

@ -51,6 +51,7 @@ enum OverwriteFiles {
}; };
extern bool use_gui; extern bool use_gui;
extern bool verbose;
extern RunMode run_mode; extern RunMode run_mode;
extern OverwriteFiles force_overwrite; extern OverwriteFiles force_overwrite;

View File

@ -66,6 +66,9 @@ using namespace lyx::support;
namespace lyx { namespace lyx {
// Dummy verbose support
bool verbose = false;
// Dummy LyXRC support // Dummy LyXRC support
struct LyXRC { struct LyXRC {
string icon_set; string icon_set;

View File

@ -195,6 +195,10 @@ void GuiProgressView::clearText()
void GuiProgressView::appendLyXErrText(QString const & text) void GuiProgressView::appendLyXErrText(QString const & text)
{ {
// Skip verbose messages meant for the terminal
if (text.startsWith("\nRunning:"))
return;
widget_->outTE->moveCursor(QTextCursor::End); widget_->outTE->moveCursor(QTextCursor::End);
widget_->outTE->insertPlainText(text); widget_->outTE->insertPlainText(text);
widget_->outTE->ensureCursorVisible(); widget_->outTE->ensureCursorVisible();

View File

@ -23,6 +23,7 @@
#include "support/os.h" #include "support/os.h"
#include "support/ProgressInterface.h" #include "support/ProgressInterface.h"
#include "LyX.h"
#include "LyXRC.h" #include "LyXRC.h"
#include <cstdlib> #include <cstdlib>
@ -239,7 +240,10 @@ int Systemcall::startscript(Starttype how, string const & what,
bool process_events) bool process_events)
{ {
string const what_ss = commandPrep(what); string const what_ss = commandPrep(what);
LYXERR(Debug::INFO,"Running: " << what_ss); if (verbose)
lyxerr << "\nRunning: " << what_ss << endl;
else
LYXERR(Debug::INFO,"Running: " << what_ss);
string infile; string infile;
string outfile; string outfile;

View File

@ -21,6 +21,7 @@
#include <config.h> #include <config.h>
#include "LyX.h"
#include "LyXRC.h" #include "LyXRC.h"
#include "support/filetools.h" #include "support/filetools.h"
@ -995,6 +996,11 @@ cmd_ret const runCommand(string const & cmd)
// pstream (process stream), with the // pstream (process stream), with the
// variants ipstream, opstream // variants ipstream, opstream
if (verbose)
lyxerr << "\nRunning: " << cmd << endl;
else
LYXERR(Debug::INFO,"Running: " << cmd);
#if defined (_WIN32) #if defined (_WIN32)
STARTUPINFO startup; STARTUPINFO startup;
PROCESS_INFORMATION process; PROCESS_INFORMATION process;

View File

@ -47,6 +47,13 @@ namespace Alert {
} }
//
// Dummy verbose support
//
bool verbose = false;
// //
// Dummy LyXRC support // Dummy LyXRC support
// //