diff options
-rw-r--r-- | pkgrel.1 | 12 | ||||
-rw-r--r-- | pkgrel.c | 5 | ||||
-rwxr-xr-x | test.sh | 3 |
3 files changed, 15 insertions, 5 deletions
@@ -1,12 +1,13 @@ .TH pkgrel 1 "2024-01-06" .SH NAME -pkgrel \- print out pkgrel number according to git repository history +pkgrel - print out pkgrel number according to git repository history .SH SYNOPSIS .B pkgrel .RI [ prefix ] .br .B pkgrel -.RB [ \-d ] +.RB [ \-\- ] +.B \-d .SH DESCRIPTION This program will check the history of the .I PKGBUILD @@ -28,7 +29,12 @@ option sets .I prefix to a handy constant .BR pkgrel= -making the final output take a form of a shell variable assignment. +making the final output take a form of a shell variable assignment. Special option +.B \-\- +allows to use literal +.B \-d +as +.IR prefix . .SH EXIT STATUS 0 will be returned on successful run and the pkgrel number will be printed to standard output. .PP @@ -118,13 +118,14 @@ parse_args(const int argc, char* argv[]) { int opt; const char* prefix = NULL; - while (-1 != (opt = getopt(argc, argv, ":d"))) { + while (NULL == prefix && -1 != (opt = getopt(argc, argv, ":d"))) { switch (opt) { case 'd': prefix = "pkgrel="; break; default: - break; // Accept anything but -d without prior -- + prefix = argv[optind - 1]; // Use first option that is not -d as a normal prefix, too. + break; } } if (NULL == prefix) { @@ -108,6 +108,9 @@ test_prefix() { test "$($pkgrel)" = "1" || exit 1 test "$($pkgrel pkgrel=)" = "pkgrel=1" || exit 1 test "$($pkgrel -d)" = "pkgrel=1" || exit 1 + test "$($pkgrel -- -d)" = "-d1" || exit 1 + test "$($pkgrel -a)" = "-a1" || exit 1 + test "$($pkgrel -a -b -c -d)" = "-a1" || exit 1 test "$($pkgrel a= b= c=)" = "a=1" || exit 1 } |