1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
From: Moritz Schlarb <schlarbm@uni-mainz.de>
Date: Tue, 8 Oct 2019 12:10:12 +0200
Subject: Add cli help and version option
Forwarded: https://github.com/haiwen/seafile-client/pull/1223
---
src/main.cpp | 39 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/src/main.cpp b/src/main.cpp
index 6783ee2..800fd90 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -74,11 +74,42 @@ void setupSettingDomain()
QCoreApplication::setApplicationName(QString("%1 Client").arg(getBrand()));
}
+void do_version() {
+ // from src/ui/about-dialog.cpp
+ QString version_text = QString("%1 Client %2")
+ .arg(getBrand())
+ .arg(STRINGIZE(SEAFILE_CLIENT_VERSION))
+#ifdef SEAFILE_CLIENT_REVISION
+ .append(" REV %1")
+ .arg(STRINGIZE(SEAFILE_CLIENT_REVISION))
+#endif
+ ;
+ printf("%s\n", toCStr(version_text));
+}
+
+void do_help(int argc, char *argv[]) {
+ printf("Usage: %s [options]\n", argv[0]);
+ printf("\n");
+ printf("Options:\n");
+ printf(" -V,--version\n");
+ printf(" -h,--help\n");
+ printf(" -c,--config-dir=<ccnet_conf_dir>\n");
+ printf(" -d,--data-dir=<seafile_data_dir>\n");
+ printf(" -K,--stop\n");
+ printf(" -D,--delay\n");
+ printf(" -X,--remove-user-data\n");
+ printf(" -f,--open-local-file=<url>\n");
+ printf(" --stdout\n");
+ printf(" -P,--ping\n");
+}
+
void handleCommandLineOption(int argc, char *argv[])
{
int c;
- static const char *short_options = "KDXPc:d:f:";
+ static const char *short_options = "VhKDXPc:d:f:";
static const struct option long_options[] = {
+ { "version", no_argument, NULL, 'V' },
+ { "help", no_argument, NULL, 'h' },
{ "config-dir", required_argument, NULL, 'c' },
{ "data-dir", required_argument, NULL, 'd' },
{ "stop", no_argument, NULL, 'K' },
@@ -93,6 +124,12 @@ void handleCommandLineOption(int argc, char *argv[])
while ((c = getopt_long (argc, argv, short_options,
long_options, NULL)) != EOF) {
switch (c) {
+ case 'V':
+ do_version();
+ exit(0);
+ case 'h':
+ do_help(argc, argv);
+ exit(0);
case 'c':
g_setenv ("CCNET_CONF_DIR", optarg, 1);
break;
|