]> git.sesse.net Git - plocate/commitdiff
Add a --version option.
authorSteinar H. Gunderson <steinar+git@gunderson.no>
Sat, 10 Oct 2020 18:39:44 +0000 (20:39 +0200)
committerSteinar H. Gunderson <steinar+git@gunderson.no>
Sat, 10 Oct 2020 19:25:21 +0000 (21:25 +0200)
meson.build
plocate.cpp

index 070a804fb89cea93e02a793e53893b928edbc422..a37a89f9ca8ce1beaca90d45b3a1c1a2f3701c60 100644 (file)
@@ -1,5 +1,8 @@
 project('plocate', 'cpp', default_options: ['buildtype=debugoptimized','cpp_std=c++17'], version: '1.0.0-pre')
 
+# Make the version available as a #define.
+add_project_arguments('-DPLOCATE_VERSION="' + meson.project_version() + '"', language: 'cpp')
+
 cxx = meson.get_compiler('cpp')
 uringdep = dependency('liburing', required: false)
 zstddep = dependency('libzstd')
index c4011c9888b3b0f86c12132b0207dcd951332aa1..54d3c796ff82a3bb2630d6cba85e0de3b133141a 100644 (file)
@@ -584,6 +584,17 @@ void usage()
        printf("  -i, --ignore-case      ignore case distinctions when matching patterns\n");
        printf("  -l, --limit, -n LIMIT  limit output (or counting) to LIMIT entries\n");
        printf("  -0, --null             separate entries with NUL on output\n");
+       printf("  -V, --version          print version information\n");
+}
+
+void version()
+{
+       printf("plocate %s\n", PLOCATE_VERSION);
+       printf("Copyright 2020 Steinar H. Gunderson\n");
+       printf("License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl.html>.\n");
+       printf("This is free software: you are free to change and redistribute it.\n");
+       printf("There is NO WARRANTY, to the extent permitted by law.\n");
+       exit(0);
 }
 
 int main(int argc, char **argv)
@@ -595,6 +606,7 @@ int main(int argc, char **argv)
                { "ignore-case", no_argument, 0, 'i' },
                { "limit", required_argument, 0, 'l' },
                { "null", no_argument, 0, '0' },
+               { "version", no_argument, 0, 'V' },
                { "debug", no_argument, 0, 'D' },  // Not documented.
                { 0, 0, 0, 0 }
        };
@@ -602,7 +614,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        for (;;) {
                int option_index = 0;
-               int c = getopt_long(argc, argv, "cd:hil:n:0D", long_options, &option_index);
+               int c = getopt_long(argc, argv, "cd:hil:n:0VD", long_options, &option_index);
                if (c == -1) {
                        break;
                }
@@ -629,6 +641,9 @@ int main(int argc, char **argv)
                case 'D':
                        use_debug = true;
                        break;
+               case 'V':
+                       version();
+                       break;
                default:
                        exit(1);
                }