commit: 76e3768d42321c3a320b8be294a7c9137dcbc939
parent c131b79aced45cdf563ce528281225827ab239a1
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 25 Jul 2025 01:37:42 +0200
cmd/mv: add support for long options
Diffstat:
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/cmd/mv.c b/cmd/mv.c
@@ -11,6 +11,7 @@
#define _NETBSD_SOURCE
#endif
+#include "../config.h"
#include "../libutils/consent.h"
#include "../libutils/fs.h"
#include "../libutils/getopt_nolong.h"
@@ -27,6 +28,9 @@
#include <string.h> // strcmp
#include <sys/stat.h> // stat, S_ISDIR
#include <unistd.h> // getopt
+#ifdef HAS_GETOPT_LONG
+#include <getopt.h>
+#endif
// Workaround against GNU glibc
// https://sourceware.org/bugzilla/show_bug.cgi?id=18228
@@ -408,7 +412,24 @@ main(int argc, char *argv[])
.sep = "",
};
+#ifdef HAS_GETOPT_LONG
+ // Strictly for GNUisms compatibility so no long-only options
+ // clang-format off
+ static struct option opts[] = {
+ {"force", no_argument, NULL, 'f'},
+ {"interactive", no_argument, NULL, 'i'},
+ {"no-clobber", no_argument, NULL, 'n'},
+ {"target-directory", required_argument, NULL, 't'},
+ {"verbose", no_argument, NULL, 'v'},
+ {0, 0, 0, 0},
+ };
+ // clang-format on
+
+ // Need + as first character to get POSIX-style option parsing
+ for(int c = -1; (c = getopt_long(argc, argv, "+:fint:v", opts, NULL)) != -1;)
+#else
for(int c = -1; (c = getopt_nolong(argc, argv, ":fint:v")) != -1;)
+#endif
{
switch(c)
{