From 34925fbd51325e53f5708fc0a5ad4fba25652ba5 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sat, 31 Aug 2013 13:34:30 +0300 Subject: [PATCH] [RFC PATCH 1/2] cli: add support for global options that get passed to sub-commands --- 60/d7471f8e64dc20a4f9448faf8aad086e3d019b | 183 ++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 60/d7471f8e64dc20a4f9448faf8aad086e3d019b diff --git a/60/d7471f8e64dc20a4f9448faf8aad086e3d019b b/60/d7471f8e64dc20a4f9448faf8aad086e3d019b new file mode 100644 index 000000000..dff59abdb --- /dev/null +++ b/60/d7471f8e64dc20a4f9448faf8aad086e3d019b @@ -0,0 +1,183 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 92D5642114C + for ; Sat, 31 Aug 2013 23:12:02 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id as0yIQl0xuyV for ; + Sat, 31 Aug 2013 23:11:55 -0700 (PDT) +Received: from mail-ee0-f49.google.com (mail-ee0-f49.google.com + [74.125.83.49]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + 9138B4092A1 for ; Sat, 31 Aug 2013 03:34:34 -0700 + (PDT) +Received: by mail-ee0-f49.google.com with SMTP id d41so1357926eek.22 + for ; Sat, 31 Aug 2013 03:34:33 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id; + bh=9GgMlPzsIeZ0/remkd5X4LIyibKDBPYYIr/ucCmWp9k=; + b=GH0V1OH0JcJUg7Y7OnYk91sZufBIHXu77wxe/7bZv/MmvlaGA2KEJbaquG36V+ffTd + PtpezAVUNv+B0CdxiFASKi61OyoFiWmBGUvpNjGKM8Epu1SlLziSbBMTfnifvubeo3os + B0qvu0NtQKHfS2082mCHLGf3cO5j0vT/jDW5I9MQvvUQ+GuTg0tmRZHhis2j3t+S3JdE + IM6Hy63P6IW9YVobvXKv+Btt/QJ8zhFi+qLFWrz7QFPKUIZlUAdOGvOOx7MH3hOPd8CC + 4dJnCLoDmXxaDfzWm+gppvN8j6sAbUq/iVoyiRnf+GYG7cwot7SjlO/XBG4BDR+sbZwa + lLtw== +X-Gm-Message-State: + ALoCoQl/J+RIln6oP4/RTHYXAj0KTvap2hAYeZvq4qksP/yenVfXVH13zFDcUx08csFsq88pS/pb +X-Received: by 10.15.26.7 with SMTP id m7mr2355856eeu.56.1377945272020; + Sat, 31 Aug 2013 03:34:32 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. + [88.195.111.91]) + by mx.google.com with ESMTPSA id r48sm4021354eev.14.1969.12.31.16.00.00 + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sat, 31 Aug 2013 03:34:31 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [RFC PATCH 1/2] cli: add support for global options that get passed + to sub-commands +Date: Sat, 31 Aug 2013 13:34:30 +0300 +Message-Id: + <08036456064699510ef832f0c6740d98d324d185.1377945239.git.jani@nikula.org> +X-Mailer: git-send-email 1.7.10.4 +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 01 Sep 2013 06:12:02 -0000 + +This allows sub-commands to have access to global options. +--- + notmuch-client.h | 21 +++++++++++++++++++++ + notmuch-config.c | 29 +++++++++++++++++++++++++++++ + notmuch.c | 10 ++++++++++ + 3 files changed, 60 insertions(+) + +diff --git a/notmuch-client.h b/notmuch-client.h +index afb0ddf..5656426 100644 +--- a/notmuch-client.h ++++ b/notmuch-client.h +@@ -320,6 +320,27 @@ notmuch_config_set_search_exclude_tags (notmuch_config_t *config, + const char *list[], + size_t length); + ++/* global options */ ++typedef struct _notmuch_global_options { ++ notmuch_bool_t debug; ++ notmuch_bool_t verbose; ++ notmuch_bool_t no_hooks; ++} notmuch_global_options_t; ++ ++void ++notmuch_global_set (notmuch_config_t *config, ++ const notmuch_global_options_t *global_options); ++ ++notmuch_bool_t ++notmuch_global_get_debug (notmuch_config_t *config); ++ ++notmuch_bool_t ++notmuch_global_get_verbose (notmuch_config_t *config); ++ ++notmuch_bool_t ++notmuch_global_get_no_hooks (notmuch_config_t *config); ++ ++ + int + notmuch_run_hook (const char *db_path, const char *hook); + +diff --git a/notmuch-config.c b/notmuch-config.c +index 6845e3c..4cb29eb 100644 +--- a/notmuch-config.c ++++ b/notmuch-config.c +@@ -118,6 +118,9 @@ struct _notmuch_config { + notmuch_bool_t maildir_synchronize_flags; + const char **search_exclude_tags; + size_t search_exclude_tags_length; ++ ++ /* global options */ ++ notmuch_global_options_t global_options; + }; + + static int +@@ -883,3 +886,29 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config, + "maildir", "synchronize_flags", synchronize_flags); + config->maildir_synchronize_flags = synchronize_flags; + } ++ ++/* global options */ ++void ++notmuch_global_set (notmuch_config_t *config, ++ const notmuch_global_options_t *global_options) ++{ ++ config->global_options = *global_options; ++} ++ ++notmuch_bool_t ++notmuch_global_get_debug (notmuch_config_t *config) ++{ ++ return config->global_options.debug; ++} ++ ++notmuch_bool_t ++notmuch_global_get_verbose (notmuch_config_t *config) ++{ ++ return config->global_options.verbose; ++} ++ ++notmuch_bool_t ++notmuch_global_get_no_hooks (notmuch_config_t *config) ++{ ++ return config->global_options.no_hooks; ++} +diff --git a/notmuch.c b/notmuch.c +index 78d29a8..11cdfd7 100644 +--- a/notmuch.c ++++ b/notmuch.c +@@ -252,11 +252,19 @@ main (int argc, char *argv[]) + notmuch_bool_t print_help=FALSE, print_version=FALSE; + int opt_index; + int ret = 0; ++ notmuch_global_options_t global_options = { ++ .debug = FALSE, ++ .verbose = FALSE, ++ .no_hooks = FALSE, ++ }; + + notmuch_opt_desc_t options[] = { + { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 }, + { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 }, + { NOTMUCH_OPT_STRING, &config_file_name, "config", 'c', 0 }, ++ { NOTMUCH_OPT_BOOLEAN, &global_options.debug, "debug", 'd', 0 }, ++ { NOTMUCH_OPT_BOOLEAN, &global_options.verbose, "verbose", 'V', 0 }, ++ { NOTMUCH_OPT_BOOLEAN, &global_options.no_hooks, "no-hooks", 'N', 0 }, + { 0, 0, 0, 0, 0 } + }; + +@@ -300,6 +308,8 @@ main (int argc, char *argv[]) + if (!config) + return 1; + ++ notmuch_global_set (config, &global_options); ++ + ret = (command->function)(config, argc - opt_index, argv + opt_index); + + notmuch_config_close (config); +-- +1.7.10.4 + -- 2.26.2