From e032b97d890c0d7c4e7c8b75400c61d80e18cbf7 Mon Sep 17 00:00:00 2001
From: Juraj Fedel <wtxnh-scribus@yahoo.com.au>
Date: Sat, 10 Oct 2015 13:55:18 +0200
Subject: [PATCH 5/7] Strange use of -- delimiter

Scribus usage of -- delimiter is not as it is used in most other unix
programs. It serves two distinct function: as a delimiter to -pa option
if it is used with only one flag and as delimiter for all options if it
is used outside -pa (-pa option always consume two option that follows
it - one of then can be -- which is ignored). Now -- can be used
multiple times:

$ scribus-1.5.1.svn  -py arg_scr.py -g -pa -flag1 -- -pa -arg2 val2 -pa -flag3  --lang ru -- document.sla

This usage of -- and -pa options is unusual and verbose. I propose for
-pa option to collect all arguments until -- or end of CLI so above
command can be written as follows:

$ scribus-1.5.1.svn --lang ru -py arg_scr.py -g -pa -flag1 -arg2 val2 -flag3 -- document.sla

This is less verbose and -- delimiter can be used at most once (as in
other programs). It has one caveat: -pa option must be last option used
in commandline (before -- or end of line). I think the tradeof is good
(see next patch:)
---
 scribus/scribusapp.cpp | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/scribus/scribusapp.cpp b/scribus/scribusapp.cpp
index 6543ad2..07bcb35 100644
--- a/scribus/scribusapp.cpp
+++ b/scribus/scribusapp.cpp
@@ -169,17 +169,15 @@ void ScribusQApp::parseCommandLine()
 	for( ; argi < argsc; argi++) { //handle options (not positional parameters)
 		arg = args[argi];
 
-		if (arg == ARG_SCRIPTARG || arg == ARG_SCRIPTARG_SHORT) { //needs to be first to give precedence to script argument name over scribus' options
-			if (++argi < argsc && (args[argi] != CMD_OPTIONS_END)) {
+		if (arg == ARG_SCRIPTARG || arg == ARG_SCRIPTARG_SHORT) {
+			while (++argi < argsc && (args[argi] != CMD_OPTIONS_END)) {
 				pythonScriptArgs.append(args[argi]); // script argument
-			} else {
-				std::cout << tr("Invalid argument use: '%1' requires to be followed by <argument> [value]").arg(arg).toLocal8Bit().data() << std::endl;
-				showUsage();
-				std::exit(EXIT_FAILURE);
 			}
-			if (++argi < argsc && !args[argi].startsWith("-")) {   // arg value
-				pythonScriptArgs.append( QFile::decodeName(args[argi].toLocal8Bit()) );
+			// We reached end of all arguments or CMD_OPTIONS_END marker. Stop parsing options
+			if (argi < argsc) {
+				argi++; // skip CMD_OPTIONS_END
 			}
+			break;
 		}
 		else if ((arg == ARG_LANG || arg == ARG_LANG_SHORT)) {
 			if  (++argi < argsc)
-- 
2.1.4

