Skip to content

Commit b4561a9

Browse files
committedNov 22, 2015
introduce a new command line option '--' to the main app
all arguments after this option are treated as files, not options includes a test
1 parent 91ad208 commit b4561a9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
 

‎src/app/main.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ void usage( std::string const & appName )
133133
<< "\t[--dxf-scale-denom scale]\tscale for dxf output\n"
134134
<< "\t[--dxf-encoding encoding]\tencoding to use for dxf output\n"
135135
<< "\t[--dxf-preset visiblity-preset]\tlayer visibility preset to use for dxf output\n"
136-
<< "\t[--help]\t\tthis text\n\n"
136+
<< "\t[--help]\t\tthis text\n"
137+
<< "\t[--]\t\ttreat all following arguments as FILEs\n\n"
137138
<< " FILE:\n"
138139
<< " Files specified on the command line can include rasters,\n"
139140
<< " vectors, and QGIS project files (.qgs): \n"
@@ -683,6 +684,11 @@ int main( int argc, char *argv[] )
683684
{
684685
dxfPreset = args[++i];
685686
}
687+
else if ( arg == "--" )
688+
{
689+
for ( i++; i < args.size(); ++i )
690+
myFileList.append( QDir::toNativeSeparators( QFileInfo( args[i] ).absoluteFilePath() ) );
691+
}
686692
else
687693
{
688694
myFileList.append( QDir::toNativeSeparators( QFileInfo( args[i] ).absoluteFilePath() ) );

‎tests/src/python/test_qgsappstartup.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ def testPyQgisStartupEnvVar(self):
165165
timeOut=15,
166166
env={'PYQGIS_STARTUP': testmod}), msg
167167

168+
def testOptionsAsFiles(self):
169+
# verify QGIS accepts filenames that match options after the special option '--'
170+
# '--help' should return immediatly (after displaying the usage hints)
171+
# '-- --help' should not exit but try (and probably fail) to load a layer called '--help'
172+
for t in [(False, ['--help']), (True, ['--', '--help'])]:
173+
assert t[0] == self.doTestStartup(option="--configpath",
174+
testDir=os.path.join(self.TMP_DIR, 'test_optionsAsFiles'),
175+
testFile="qgis.db",
176+
timeOut=15,
177+
additionalArguments = t[1]), "additional arguments: %s" % ' '.join(t[1])
178+
168179

169180
if __name__ == '__main__':
170181
# look for qgis bin path

0 commit comments

Comments
 (0)
Please sign in to comment.