From c8dcfebd2293279eb8aefeffa11b8a35a233cf2e Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 6 Jan 2024 18:33:48 +0100 Subject: Added -- -d --- pkgrel.1 | 12 +++++++++--- pkgrel.c | 5 +++-- test.sh | 3 +++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pkgrel.1 b/pkgrel.1 index 5d1965d..1a5d912 100644 --- a/pkgrel.1 +++ b/pkgrel.1 @@ -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 diff --git a/pkgrel.c b/pkgrel.c index 961ecbd..fe25fe4 100644 --- a/pkgrel.c +++ b/pkgrel.c @@ -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) { diff --git a/test.sh b/test.sh index 9c1e8c7..742e823 100755 --- a/test.sh +++ b/test.sh @@ -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 } -- cgit v1.1