shithub: orca

Download patch

ref: df82ab8d234c6834f12d804cc30773feba129fd2
parent: a51f2d47ec3394faa06cda5948fc27e14287212b
author: cancel <cancel@cancel.fm>
date: Sat Jan 25 23:48:36 EST 2020

Add --quiet option to cli

--- a/cli_main.c
+++ b/cli_main.c
@@ -13,6 +13,7 @@
       "    -t <number>   Number of timesteps to simulate.\n"
       "                  Must be 0 or a positive integer.\n"
       "                  Default: 1\n"
+      "    -q or --quiet Don't print the result to stdout.\n"
       "    -h or --help  Print this message and exit.\n"
       );
   // clang-format on
@@ -20,13 +21,15 @@
 
 int main(int argc, char **argv) {
   static struct option cli_options[] = {{"help", no_argument, 0, 'h'},
+                                        {"quiet", no_argument, 0, 'q'},
                                         {NULL, 0, NULL, 0}};
 
   char *input_file = NULL;
   int ticks = 1;
+  bool print_output = true;
 
   for (;;) {
-    int c = getopt_long(argc, argv, "t:h", cli_options, NULL);
+    int c = getopt_long(argc, argv, "t:qh", cli_options, NULL);
     if (c == -1)
       break;
     switch (c) {
@@ -40,6 +43,9 @@
         return 1;
       }
       break;
+    case 'q':
+      print_output = false;
+      break;
     case 'h':
       usage();
       return 0;
@@ -110,7 +116,8 @@
   }
   mbuf_reusable_deinit(&mbuf_r);
   oevent_list_deinit(&oevent_list);
-  field_fput(&field, stdout);
+  if (print_output)
+    field_fput(&field, stdout);
   field_deinit(&field);
   return 0;
 }