summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-01-06 18:33:48 +0100
committerAki <please@ignore.pl>2024-01-06 18:33:48 +0100
commitc8dcfebd2293279eb8aefeffa11b8a35a233cf2e (patch)
tree1b6512ac456e6c562f829e270af522a1aed4b93f
parentb8e8b02a1f4d7a398fc7c10de98e51bf1945b04f (diff)
downloadpkgrel-c8dcfebd2293279eb8aefeffa11b8a35a233cf2e.zip
pkgrel-c8dcfebd2293279eb8aefeffa11b8a35a233cf2e.tar.gz
pkgrel-c8dcfebd2293279eb8aefeffa11b8a35a233cf2e.tar.bz2
Added -- -dHEADmaster
-rw-r--r--pkgrel.112
-rw-r--r--pkgrel.c5
-rwxr-xr-xtest.sh3
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
}