From 67365119d357c67455265c9b5d8e3e6937341419 Mon Sep 17 00:00:00 2001
From: Juraj Fedel <wtxnh-scribus@yahoo.com.au>
Date: Sat, 10 Oct 2015 14:54:41 +0200
Subject: [PATCH 6/7] Merge ARG_SCRIPTARG with ARG_PYTHONSCRIPT

This  will enable --python-script to specify script to run and all the
arguments to pass into script with single option (--python-arg option is
obsolete with this patch)

Now --python-script option must be used last before -- or end of
command line.

Usage:

$ scribus-1.5.1.svn  -g -py arg_scr.py -flag1 -arg2 val2 -flag3 -- document.sla
---
 scribus/scribusapp.cpp | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/scribus/scribusapp.cpp b/scribus/scribusapp.cpp
index 07bcb35..63563ad 100644
--- a/scribus/scribusapp.cpp
+++ b/scribus/scribusapp.cpp
@@ -72,7 +72,6 @@ for which a new license (GPL+exception) is in place.
 #define ARG_UPGRADECHECK "--upgradecheck"
 #define ARG_TESTS "--tests"
 #define ARG_PYTHONSCRIPT "--python-script"
-#define ARG_SCRIPTARG "--python-arg"
 #define CMD_OPTIONS_END "--"
 
 #define ARG_VERSION_SHORT "-v"
@@ -89,7 +88,6 @@ for which a new license (GPL+exception) is in place.
 #define ARG_UPGRADECHECK_SHORT "-u"
 #define ARG_TESTS_SHORT "-T"
 #define ARG_PYTHONSCRIPT_SHORT "-py"
-#define ARG_SCRIPTARG_SHORT "-pa"
 
 // Qt wants -display not --display or -d
 #define ARG_DISPLAY_QT "-display"
@@ -169,7 +167,18 @@ void ScribusQApp::parseCommandLine()
 	for( ; argi < argsc; argi++) { //handle options (not positional parameters)
 		arg = args[argi];
 
-		if (arg == ARG_SCRIPTARG || arg == ARG_SCRIPTARG_SHORT) {
+		if (arg == ARG_PYTHONSCRIPT || arg == ARG_PYTHONSCRIPT_SHORT) {
+			if (argi+1 == argsc) {
+				std::cout << tr("Option %1 require an argument.").arg(arg).toLocal8Bit().data() << std::endl;
+				std::exit(EXIT_FAILURE);
+			}
+			pythonScript = QFile::decodeName(args[argi + 1].toLocal8Bit());
+			if (!QFileInfo(pythonScript).exists()) {
+				std::cout << tr("Python script %1 does not exist, aborting.").arg(pythonScript).toLocal8Bit().data() << std::endl;
+				std::exit(EXIT_FAILURE);
+			}
+			++argi;
+
 			while (++argi < argsc && (args[argi] != CMD_OPTIONS_END)) {
 				pythonScriptArgs.append(args[argi]); // script argument
 			}
@@ -243,18 +252,6 @@ void ScribusQApp::parseCommandLine()
 		} else if (strncmp(arg.toLocal8Bit().data(),"-psn_",4) == 0)
 		{
 			// Andreas Vox: Qt/Mac has -psn_blah flags that must be accepted.
-		} else if (arg == ARG_PYTHONSCRIPT || arg == ARG_PYTHONSCRIPT_SHORT) {
-			if (argi+1 == argsc) {
-				std::cout << tr("Option %1 require an argument.").arg(arg).toLocal8Bit().data() << std::endl;
-				std::exit(EXIT_FAILURE);
-			}
-			pythonScript = QFile::decodeName(args[argi + 1].toLocal8Bit());
-			if (!QFileInfo(pythonScript).exists()) {
-				std::cout << tr("Python script %1 does not exist, aborting.").arg(pythonScript).toLocal8Bit().data() << std::endl;
-				std::exit(EXIT_FAILURE);
-			} else {
-				++argi;
-			}
 		} else if (arg == CMD_OPTIONS_END) { //double dash, indicates end of command line options, see http://unix.stackexchange.com/questions/11376/what-does-double-dash-mean-also-known-as-bare-double-dash
 			argi++;
 			break;
@@ -531,8 +528,7 @@ void ScribusQApp::showUsage()
 	printArgLine(ts, ARG_PROFILEINFO_SHORT, ARG_PROFILEINFO, tr("Show location of ICC profile information on console while starting") );
 	printArgLine(ts, ARG_UPGRADECHECK_SHORT, ARG_UPGRADECHECK, tr("Download a file from the Scribus website and show the latest available version") );
 	printArgLine(ts, ARG_VERSION_SHORT, ARG_VERSION, tr("Output version information and exit") );
-	printArgLine(ts, ARG_PYTHONSCRIPT_SHORT, qPrintable(QString("%1 <%2>").arg(ARG_PYTHONSCRIPT).arg(tr("filename"))), tr("Run filename in Python scripter") );
-	printArgLine(ts, ARG_SCRIPTARG_SHORT, qPrintable(QString("%1 <%2> [%3]").arg(ARG_SCRIPTARG).arg(tr("argument")).arg(tr("value"))), tr("Argument passed on to python script, with an optional value, no effect without -py") );
+	printArgLine(ts, ARG_PYTHONSCRIPT_SHORT, qPrintable(QString("%1 <%2> [%3] ").arg(ARG_PYTHONSCRIPT).arg(tr("script")).arg(tr("arguments ..."))), tr("Run script in Python [with optional arguments]. This option must be last option used") );
 	printArgLine(ts, ARG_NOGUI_SHORT, ARG_NOGUI, tr("Do not start GUI") );
 	ts << (QString("     %1").arg(CMD_OPTIONS_END,-39)) << tr("Explicit end of command line options"); endl(ts);
  	
-- 
2.1.4

