View Issue Details

IDProjectCategoryView StatusLast Update
0013415ScribusUser Interfacepublic2015-11-27 14:11
ReporterjurajF Assigned Tocbradney  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformqemuOSLinuxOS VersionDebian 8/Jessie
Product Version1.5.0 
Fixed in Version1.5.1svn 
Summary0013415: [CLI] Changing multiple flag rules
DescriptionContains 3 patches from 0013408
split in to several tickets for better readability


0005-Strange-use-of-delimiter.patch
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 :)


0006-Merge-ARG_SCRIPTARG-with-ARG_PYTHONSCRIPT.patch
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


0007-Allow-sla-files-to-be-intermixed-with-other-options.patch

This will remove the requirement for all sla files to be specified at
the end of command line. Now it is possible to specify sla document at
any place (before --python-script option):

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

If you have some --funny-name.sla (beginning with dash) you still need
to use -- delimiter (this is main reason for existence of -- delimiter
in most programs):

$ scribus-1.5.1.svn document.sla -g -py arg_scr.py -flag1 -arg2 val2 -flag3 -- --funny-name.sla

This last patch can be ignored if you find it unneeded (at commiter discretion).
Additional InformationCloned from 0013408
TagsNo tags attached.
PatchYes

Relationships

related to 0013408 closedcbradney [CLI] --prefs option without provided file causes crash 
related to 0013414 closedcbradney [CLI] --lang issues 
related to 0013413 closedcbradney [CLI] Error-message-wrong-and-too-verbose 
related to 0013452 closedfschmid Can not open ".autosave" file: "is not in an acceptable format" 

Activities

Kunda

2015-10-11 23:38

updater   ~0036638

Coolness. Thanks Juraj. We should get Berteh in to this conversation as well. I'll try to ping him.

berteh

2015-10-11 23:38

reporter   ~0036639

Hi Juraj, thanks for the various improvements you brought esp. improving the feedback when arguments are missing a required value (filename in these cases).

just one note regarding your use of "--". I think it's wrong to allow multiple use of it. It usually (as in "in other places where it's used) denotes the end of options and the beginning of positional arguments... and I think it should stay that way.

The reason you mention for needing to enable multiple use was actually not needed, as -pa works just fine if you provide it with just a flag name and then follow with more options (it will detect the starting "-" of the following option and skip looking for its (optional) argument value)... so the only place you needed the "--" is indeed at the very end of options sequence, to make sure the positional arguments (scribus files) are not consumed by -pa.

[it was handled in the line
if (++argi < argsc && !args[argi].startsWith("-")) { // arg value
that you removed in your patch "strange use of delimiter") ]



That being said, I agree with you that forcing -pa to be the last option and consume all that's left of command line (before an optional --) would be less verbose. It's just that othes preferred not having that mechanism, see aoloe at https://github.com/scribusproject/scribus/pull/19#issuecomment-128313027, and cbradney at http://bugs.scribus.net/view.php?id=13311#c36165

... so I guess that part is not an option for the core devs of scribus.

Kunda

2015-10-11 23:38

updater   ~0036640

Last edited: 2015-10-11 23:46

Cloned this issue from 0013408 to split up the ticket so we can talk about the different patches in ea. ticket.

Kunda

2015-10-11 23:39

updater  

0005-Strange-use-of-delimiter.patch (2,601 bytes)   
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

Kunda

2015-10-11 23:40

updater  

0006-Merge-ARG_SCRIPTARG-with-ARG_PYTHONSCRIPT.patch (4,471 bytes)   
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

Kunda

2015-10-11 23:40

updater  

0007-Allow-sla-files-to-be-intermixed-with-other-options.patch (1,551 bytes)   
From 1bb061db79965928aad10d021b1ffa173536b549 Mon Sep 17 00:00:00 2001
From: Juraj Fedel <wtxnh-scribus@yahoo.com.au>
Date: Sat, 10 Oct 2015 15:07:18 +0200
Subject: [PATCH 7/7] Allow sla files to be intermixed with other options

This will remove the requirement for all sla files to be specified at
the end of command line. Now it is possible to specify sla document at
any place (before --python-script option):

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

If you have some --funny-name.sla (beginning with dash) you still need
to use -- delimiter (this is main reason for existence of -- delimiter
in most programs):

$ scribus-1.5.1.svn document.sla -g -py arg_scr.py -flag1 -arg2 val2 -flag3 -- --funny-name.sla
---
 scribus/scribusapp.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/scribus/scribusapp.cpp b/scribus/scribusapp.cpp
index 63563ad..52e77f6 100644
--- a/scribus/scribusapp.cpp
+++ b/scribus/scribusapp.cpp
@@ -260,7 +260,13 @@ void ScribusQApp::parseCommandLine()
 				std::cout << tr("Invalid argument: %1").arg(arg).toLocal8Bit().data() << std::endl;
 				std::exit(EXIT_FAILURE);
 			}
-			break;
+			fileName = QFile::decodeName(args[argi].toLocal8Bit());
+			if (!QFileInfo(fileName).exists()) {
+				std::cout << tr("File %1 does not exist, aborting.").arg(fileName).toLocal8Bit().data() << std::endl;
+				std::exit(EXIT_FAILURE);
+			} else {
+				filesToLoad.append(fileName);
+			}
 		}
 	}
 	// parse for remaining (positional) arguments, if any
-- 
2.1.4

jurajF

2015-10-12 20:25

reporter   ~0036657

@berteh I need to apologize for two things: me not understanding how
exactly -pa options was working and me not clearly explaining what my
patch do. I did not realized that we do need to use -- as a second
argument to -pa.

The other thing is that without my patch it _is_ possible to use --
delimiter multiple times (for multiple -pa occurrences and once outside
-pa). We are both thinking that this is wrong.

In http://bugs.scribus.net/view.php?id=13311#c36165 Craig wrote:

> I guess we would accept forcing --python-arg to be last and then having all arg/values at the end

and I am hoping that he will accept such change (this simplify CLI, more
so when -pa is merged with -py option)

@Kunda Thanks for splitting my post into multiple tickets. This way less
controversial changes hopefully can be more easily accepted and the
other patches can be refined or dismissed. Originally I posted them
together because they change code in the same place and if they are not
applied in order as I ordered them some of will need to be changed. But
that is doable...

Kunda

2015-10-12 21:23

updater   ~0036658

@jurajF
Originally I posted them together because they change code in the same place and if they are not applied in order as I ordered them some of will need to be changed

I had a feeling that was the case. I'm sorry if this causes more work then needed. Thank you for understanding my intention though. Thanks again for contributing. Cheers!

Issue History

Date Modified Username Field Change
2015-10-11 23:38 Kunda New Issue
2015-10-11 23:38 Kunda Issue generated from: 0013414
2015-10-11 23:39 Kunda File Deleted: 0003-Remove-duplicated-code.patch
2015-10-11 23:39 Kunda File Deleted: 0004-Wrong-error-when-lang-does-not-have-an-argument.patch
2015-10-11 23:39 Kunda File Added: 0005-Strange-use-of-delimiter.patch
2015-10-11 23:40 Kunda File Added: 0006-Merge-ARG_SCRIPTARG-with-ARG_PYTHONSCRIPT.patch
2015-10-11 23:40 Kunda File Added: 0007-Allow-sla-files-to-be-intermixed-with-other-options.patch
2015-10-11 23:40 Kunda Description Updated
2015-10-11 23:41 Kunda Relationship added related to 0013408
2015-10-11 23:45 Kunda Relationship added related to 0013414
2015-10-11 23:45 Kunda Relationship added related to 0013413
2015-10-11 23:46 Kunda Reporter Kunda => jurajF
2015-10-11 23:46 Kunda Note Edited: 0036640
2015-10-12 20:25 jurajF Note Added: 0036657
2015-10-12 21:23 Kunda Note Added: 0036658
2015-10-29 04:44 Kunda Relationship added related to 0013452
2015-11-02 10:19 cbradney Status new => resolved
2015-11-02 10:19 cbradney Fixed in Version => 1.5.1svn
2015-11-02 10:19 cbradney Resolution open => fixed
2015-11-02 10:19 cbradney Assigned To => cbradney
2015-11-27 14:11 Kunda Status resolved => closed