Răsfoiți Sursa

curl: make --silent work stand-alone

- renamed the struct field to 'silent' to match the cmdline option
- make --show-error toggle independently of --silent
- make --silent independent of ->noprogress as well

By doing this, the three options --silent, --no-progress-meter and
--show-error should work independently of each other and also work with
and without '--no-' prefix as documented.

Reported-by: u20221022 on github
Fixes #10535
Closes #10536
Daniel Stenberg 1 an în urmă
părinte
comite
6841f2ed5f
5 a modificat fișierele cu 26 adăugiri și 34 ștergeri
  1. 3 5
      src/tool_cfgable.h
  2. 4 14
      src/tool_getparam.c
  3. 1 1
      src/tool_main.c
  4. 2 2
      src/tool_msgs.c
  5. 16 12
      src/tool_operate.c

+ 3 - 5
src/tool_cfgable.h

@@ -298,11 +298,9 @@ struct OperationConfig {
 };
 
 struct GlobalConfig {
-  int showerror;                  /* -1 == unset, default => show errors
-                                      0 => -s is used to NOT show errors
-                                      1 => -S has been used to show errors */
-  bool mute;                      /* don't show messages, --silent given */
-  bool noprogress;                /* don't show progress bar --silent given */
+  bool showerror;                 /* show errors when silent */
+  bool silent;                    /* don't show messages, --silent given */
+  bool noprogress;                /* don't show progress bar */
   bool isatty;                    /* Updated internally if output is a tty */
   FILE *errors;                   /* Error stream, defaults to stderr */
   bool errors_fopened;            /* Whether error stream isn't stderr */

+ 4 - 14
src/tool_getparam.c

@@ -2268,21 +2268,11 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
       /* use remote file's time */
       config->remote_time = toggle;
       break;
-    case 's':
-      /* don't show progress meter, don't show errors : */
-      if(toggle)
-        global->mute = global->noprogress = TRUE;
-      else
-        global->mute = global->noprogress = FALSE;
-      if(global->showerror < 0)
-        /* if still on the default value, set showerror to the reverse of
-           toggle. This is to allow -S and -s to be used in an independent
-           order but still have the same effect. */
-        global->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
+    case 's': /* --silent */
+      global->silent = toggle;
       break;
-    case 'S':
-      /* show errors */
-      global->showerror = toggle?1:0; /* toggle on if used with -s */
+    case 'S': /* --show-error */
+      global->showerror = toggle;
       break;
     case 't':
       /* Telnet options */

+ 1 - 1
src/tool_main.c

@@ -155,7 +155,7 @@ static CURLcode main_init(struct GlobalConfig *config)
 #endif
 
   /* Initialise the global config */
-  config->showerror = -1;             /* Will show errors */
+  config->showerror = FALSE;          /* show errors when silent */
   config->errors = stderr;            /* Default errors to stderr */
   config->styled_output = TRUE;       /* enable detection */
   config->parallel_max = PARALLEL_DEFAULT;

+ 2 - 2
src/tool_msgs.c

@@ -42,7 +42,7 @@ static void voutf(struct GlobalConfig *config,
                   va_list ap)
 {
   size_t width = (79 - strlen(prefix));
-  if(!config->mute) {
+  if(!config->silent) {
     size_t len;
     char *ptr;
     char *print_buffer;
@@ -132,7 +132,7 @@ void helpf(FILE *errors, const char *fmt, ...)
  */
 void errorf(struct GlobalConfig *config, const char *fmt, ...)
 {
-  if(!config->mute) {
+  if(!config->silent) {
     va_list ap;
     va_start(ap, fmt);
     voutf(config, ERROR_PREFIX, fmt, ap);

+ 16 - 12
src/tool_operate.c

@@ -396,12 +396,13 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
 #ifdef __VMS
   if(is_vms_shell()) {
     /* VMS DCL shell behavior */
-    if(!global->showerror)
+    if(global->silent && !global->showerror)
       vms_show = VMSSTS_HIDE;
   }
   else
 #endif
-    if(!config->synthetic_error && result && global->showerror) {
+    if(!config->synthetic_error && result &&
+       (!global->silent || global->showerror)) {
       const char *msg = per->errorbuffer;
       fprintf(global->errors, "curl: (%d) %s\n", result,
               (msg && msg[0]) ? msg : curl_easy_strerror(result));
@@ -413,7 +414,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
       long code = 0;
       curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
       if(code >= 400) {
-        if(global->showerror)
+        if(!global->silent || global->showerror)
           fprintf(global->errors,
                   "curl: (%d) The requested URL returned error: %ld\n",
                   CURLE_HTTP_RETURNED_ERROR, code);
@@ -446,7 +447,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
     if(!result && rc) {
       /* something went wrong in the writing process */
       result = CURLE_WRITE_ERROR;
-      if(global->showerror)
+      if(!global->silent || global->showerror)
         fprintf(global->errors, "curl: (%d) Failed writing body\n", result);
     }
   }
@@ -587,7 +588,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
         int rc;
         /* We have written data to an output file, we truncate file
          */
-        if(!global->mute)
+        if(!global->silent)
           fprintf(global->errors, "Throwing away %"
                   CURL_FORMAT_CURL_OFF_T " bytes\n",
                   outs->bytes);
@@ -597,7 +598,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
         if(ftruncate(fileno(outs->stream), outs->init)) {
           /* when truncate fails, we can't just append as then we'll
              create something strange, bail out */
-          if(global->showerror)
+          if(!global->silent || global->showerror)
             fprintf(global->errors,
                     "curl: (23) Failed to truncate file\n");
           return CURLE_WRITE_ERROR;
@@ -613,7 +614,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
         rc = fseek(outs->stream, (long)outs->init, SEEK_SET);
 #endif
         if(rc) {
-          if(global->showerror)
+          if(!global->silent || global->showerror)
             fprintf(global->errors,
                     "curl: (23) Failed seeking to end of file\n");
           return CURLE_WRITE_ERROR;
@@ -639,7 +640,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
     if(!result && rc) {
       /* something went wrong in the writing process */
       result = CURLE_WRITE_ERROR;
-      if(global->showerror)
+      if(!global->silent || global->showerror)
         fprintf(global->errors, "curl: (%d) Failed writing body\n", result);
     }
     if(result && config->rm_partial) {
@@ -799,7 +800,8 @@ static CURLcode single_transfer(struct GlobalConfig *global,
     if(!config->globoff && infiles && !inglob) {
       /* Unless explicitly shut off */
       result = glob_url(&inglob, infiles, &state->infilenum,
-                        global->showerror?global->errors:NULL);
+                        (!global->silent || global->showerror)?
+                        global->errors:NULL);
       if(result)
         break;
       config->state.inglob = inglob;
@@ -834,7 +836,8 @@ static CURLcode single_transfer(struct GlobalConfig *global,
           /* Unless explicitly shut off, we expand '{...}' and '[...]'
              expressions and return total number of URLs in pattern set */
           result = glob_url(&state->urls, urlnode->url, &state->urlnum,
-                            global->showerror?global->errors:NULL);
+                            (!global->silent || global->showerror)?
+                            global->errors:NULL);
           if(result)
             break;
           urlnum = state->urlnum;
@@ -1316,7 +1319,8 @@ static CURLcode single_transfer(struct GlobalConfig *global,
         }
 
         my_setopt_str(curl, CURLOPT_URL, per->this_url);
-        my_setopt(curl, CURLOPT_NOPROGRESS, global->noprogress?1L:0L);
+        my_setopt(curl, CURLOPT_NOPROGRESS,
+                  global->noprogress || global->silent?1L:0L);
         if(config->no_body)
           my_setopt(curl, CURLOPT_NOBODY, 1L);
 
@@ -1853,7 +1857,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
         progressbarinit(&per->progressbar, config);
 
         if((global->progressmode == CURL_PROGRESS_BAR) &&
-           !global->noprogress && !global->mute) {
+           !global->noprogress && !global->silent) {
           /* we want the alternative style, then we have to implement it
              ourselves! */
           my_setopt(curl, CURLOPT_XFERINFOFUNCTION, tool_progress_cb);