From 0637606799315a21802ff94bce448f55d82ccb9e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 10 Oct 2020 20:39:44 +0200 Subject: [PATCH] Add a --version option. --- meson.build | 3 +++ plocate.cpp | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 070a804..a37a89f 100644 --- a/meson.build +++ b/meson.build @@ -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') diff --git a/plocate.cpp b/plocate.cpp index c4011c9..54d3c79 100644 --- a/plocate.cpp +++ b/plocate.cpp @@ -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 .\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); } -- 2.39.2