]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hardlink: add --quiet option
authorKarel Zak <kzak@redhat.com>
Wed, 17 Feb 2021 10:14:54 +0000 (11:14 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 17 Feb 2021 10:50:21 +0000 (11:50 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/hardlink.1
misc-utils/hardlink.c

index d47fda5c191f345986beefa1e4a913e0c576a0ee..4665f60c2f32893d082f8f04678ef5ad6a4513e0 100644 (file)
@@ -23,6 +23,9 @@ print quick usage details to the screen.
 More verbose output. If specified once, every hardlinked file is displayed,
 if specified twice, it also shows every comparison.
 .TP
+.BR \-q ,\ \-\-quiet
+Quiet mode, don't print anything.
+.TP
 .B \-n ,\ \-\-dry\-run
 Do not act, just print what would happen
 .TP
index 88e1c4f417b507c2c2267a42ccbf01c2691d7369..ef2852a197e6e5d6c6d69378a982d72c322b0cdc 100644 (file)
@@ -42,6 +42,7 @@
 #include "xalloc.h"
 #include "strutils.h"
 #include "monotonic.h"
+#include "optutils.h"
 
 /* Use libpcre2posix if it's available */
 #ifdef HAVE_PCRE2_POSIX
@@ -56,6 +57,8 @@
 # include <sys/xattr.h>          /* listxattr, getxattr */
 #endif
 
+static int quiet;              /* don't print anything */
+
 /**
  * struct file - Information about a file
  * @st:       The stat buffer associated with the file
@@ -184,7 +187,7 @@ static void jlog(enum log_level level, const char *format, ...)
 {
     va_list args;
 
-    if (level > (unsigned int) opts.verbosity)
+    if (quiet || level > (unsigned int) opts.verbosity)
         return;
 
     va_start(args, format);
@@ -858,6 +861,7 @@ static void __attribute__((__noreturn__)) usage(void)
 
     fputs(USAGE_OPTIONS, out);
     fputs(_(" -v, --verbose              verbose output (repeat for more verbosity)\n"), out);
+    fputs(_(" -q, --quiet                quiet mode - don't print anything\n"
     fputs(_(" -n, --dry-run              don't actually link anything\n"), out);
     fputs(_(" -f, --respect-name         filenames have to be identical\n"), out);
     fputs(_(" -p, --ignore-mode          ignore changes of file mode\n"), out);
@@ -915,7 +919,7 @@ static void register_regex(struct regex_link **pregs, const char *regex)
  */
 static int parse_options(int argc, char *argv[])
 {
-    static const char optstr[] = "VhvnfpotXcmMOx:i:s:";
+    static const char optstr[] = "VhvnfpotXcmMOx:i:s:q";
     static const struct option long_options[] = {
         {"version", no_argument, NULL, 'V'},
         {"help", no_argument, NULL, 'h'},
@@ -933,11 +937,20 @@ static int parse_options(int argc, char *argv[])
         {"include", required_argument, NULL, 'i'},
         {"minimum-size", required_argument, NULL, 's'},
        {"content", no_argument, NULL, 'c'},
+       {"quiet", no_argument, NULL, 'q'},
         {NULL, 0, NULL, 0}
     };
+    static const ul_excl_t excl[] = {
+           { 'q','v' },
+           { 0 }
+    };
+    int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
     int c;
 
     while ((c = getopt_long(argc, argv, optstr, long_options, NULL)) != -1) {
+
+       err_exclusive_options(c, long_options, excl, excl_st);
+
         switch (c) {
         case 'p':
             opts.respect_mode = FALSE;
@@ -966,6 +979,9 @@ static int parse_options(int argc, char *argv[])
         case 'v':
             opts.verbosity++;
             break;
+       case 'q':
+           quiet = TRUE;
+           break;
         case 'c':
             opts.respect_mode = FALSE;
             opts.respect_name = FALSE;