Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
kaidan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linus Jahn
kaidan
Commits
df3ae429
Commit
df3ae429
authored
Jan 05, 2017
by
Linus Jahn
Committed by
GitHub
Jan 05, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add command line parser for help and version infos (#44)
parent
5d736f17
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
CMakeLists.txt
CMakeLists.txt
+2
-0
src/main.cpp
src/main.cpp
+59
-0
No files found.
CMakeLists.txt
View file @
df3ae429
...
...
@@ -7,6 +7,7 @@ project(kaidan)
set
(
APPLICATION_ID
"harbour.kaidan"
)
set
(
APPLICATION_NAME
"kaidan"
)
set
(
APPLICATION_DISPLAY_NAME
"Kaidan"
)
set
(
APPLICATION_DESCRIPTION
"Cross platform XMPP client"
)
# Version
set
(
VERSION_MAJOR 0
)
...
...
@@ -66,6 +67,7 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
APPLICATION_ID=
"
${
APPLICATION_ID
}
"
APPLICATION_NAME=
"
${
APPLICATION_NAME
}
"
APPLICATION_DISPLAY_NAME=
"
${
APPLICATION_DISPLAY_NAME
}
"
APPLICATION_DESCRIPTION=
"
${
APPLICATION_DESCRIPTION
}
"
VERSION_STRING=
"
${
VERSION_STRING
}
"
)
src/main.cpp
View file @
df3ae429
// Qt
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QDebug>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickView>
...
...
@@ -11,16 +14,72 @@
#include "RosterController.h"
#include "RosterItem.h"
enum
CommandLineParseResult
{
CommandLineOk
,
CommandLineError
,
CommandLineVersionRequested
,
CommandLineHelpRequested
};
CommandLineParseResult
parseCommandLine
(
QCommandLineParser
&
parser
,
QString
*
errorMessage
)
{
// add all possible arguments
QCommandLineOption
helpOption
=
parser
.
addHelpOption
();
QCommandLineOption
versionOption
=
parser
.
addVersionOption
();
// parse arguments
if
(
!
parser
.
parse
(
QGuiApplication
::
arguments
()))
{
*
errorMessage
=
parser
.
errorText
();
return
CommandLineError
;
}
// check for special cases
if
(
parser
.
isSet
(
versionOption
))
return
CommandLineVersionRequested
;
if
(
parser
.
isSet
(
helpOption
))
return
CommandLineHelpRequested
;
// if nothing special happened, return OK
return
CommandLineOk
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
qmlRegisterType
<
RosterController
>
(
APPLICATION_ID
,
1
,
0
,
"RosterController"
);
qmlRegisterType
<
RosterItem
>
(
APPLICATION_ID
,
1
,
0
,
"RosterItem"
);
// create a qt app
QGuiApplication
app
(
argc
,
argv
);
QGuiApplication
::
setApplicationName
(
APPLICATION_NAME
);
QGuiApplication
::
setApplicationDisplayName
(
APPLICATION_DISPLAY_NAME
);
QGuiApplication
::
setApplicationVersion
(
VERSION_STRING
);
// create parser and add a description
QCommandLineParser
parser
;
parser
.
setApplicationDescription
(
QString
(
APPLICATION_DISPLAY_NAME
)
+
" - "
+
QString
(
APPLICATION_DESCRIPTION
));
// parse the arguments
QString
commandLineErrorMessage
;
switch
(
parseCommandLine
(
parser
,
&
commandLineErrorMessage
))
{
case
CommandLineError
:
qDebug
()
<<
commandLineErrorMessage
;
return
1
;
case
CommandLineVersionRequested
:
parser
.
showVersion
();
return
0
;
case
CommandLineHelpRequested
:
parser
.
showHelp
();
return
0
;
case
CommandLineOk
:
qDebug
()
<<
"Successfully parsed command line input."
;
break
;
}
QtEventLoop
eventLoop
;
BoostNetworkFactories
networkFactories
(
&
eventLoop
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment