From df82ab8d234c6834f12d804cc30773feba129fd2 Mon Sep 17 00:00:00 2001 From: cancel Date: Sun, 26 Jan 2020 04:48:36 +0900 Subject: [PATCH] Add --quiet option to cli --- cli_main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cli_main.c b/cli_main.c index 8f7e2c5..1881ff0 100644 --- a/cli_main.c +++ b/cli_main.c @@ -13,6 +13,7 @@ static void usage(void) { " -t 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 @@ static void usage(void) { 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 @@ int main(int argc, char **argv) { return 1; } break; + case 'q': + print_output = false; + break; case 'h': usage(); return 0; @@ -110,7 +116,8 @@ int main(int argc, char **argv) { } 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; }