Skip to content

Commit ebfce9b

Browse files
authoredJun 17, 2019
Merge pull request #30198 from jgrocha/add--version-cli-option
[needs-docs] Add --version|-v cli option to qgis executable
2 parents 62b2406 + b85d42c commit ebfce9b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed
 

‎src/app/main.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ typedef SInt32 SRefCon;
113113
#include "qgsopenclutils.h"
114114
#endif
115115

116+
/**
117+
* Print QGIS version
118+
*/
119+
void version( )
120+
{
121+
const QString msg = QStringLiteral( "QGIS %1 '%2' (%3)\n" ).arg( VERSION ).arg( RELEASE_NAME ).arg( QGSVERSION );
122+
std::cout << msg.toStdString();
123+
}
124+
116125
/**
117126
* Print usage text
118127
*/
@@ -121,11 +130,10 @@ void usage( const QString &appName )
121130
QStringList msg;
122131

123132
msg
124-
<< QStringLiteral( "QGIS - " ) << VERSION << QStringLiteral( " '" ) << RELEASE_NAME << QStringLiteral( "' (" )
125-
<< QGSVERSION << QStringLiteral( ")\n" )
126133
<< QStringLiteral( "QGIS is a user friendly Open Source Geographic Information System.\n" )
127134
<< QStringLiteral( "Usage: " ) << appName << QStringLiteral( " [OPTION] [FILE]\n" )
128135
<< QStringLiteral( " OPTION:\n" )
136+
<< QStringLiteral( "\t[--version]\tdisplay version information and exit\n" )
129137
<< QStringLiteral( "\t[--snapshot filename]\temit snapshot of loaded datasets to given file\n" )
130138
<< QStringLiteral( "\t[--width width]\twidth of snapshot to emit\n" )
131139
<< QStringLiteral( "\t[--height height]\theight of snapshot to emit\n" )
@@ -173,7 +181,7 @@ void usage( const QString &appName )
173181
"QGIS command line options",
174182
MB_OK );
175183
#else
176-
std::cerr << msg.join( QString() ).toLocal8Bit().constData();
184+
std::cout << msg.join( QString() ).toLocal8Bit().constData();
177185
#endif
178186

179187
} // usage()
@@ -603,7 +611,12 @@ int main( int argc, char *argv[] )
603611
if ( arg == QLatin1String( "--help" ) || arg == QLatin1String( "-?" ) )
604612
{
605613
usage( args[0] );
606-
return 2;
614+
return EXIT_SUCCESS;
615+
}
616+
else if ( arg == QLatin1String( "--version" ) || arg == QLatin1String( "-v" ) )
617+
{
618+
version();
619+
return EXIT_SUCCESS;
607620
}
608621
else if ( arg == QLatin1String( "--nologo" ) || arg == QLatin1String( "-n" ) )
609622
{

0 commit comments

Comments
 (0)
Please sign in to comment.