* [RFC PATCH 1/2] cli: add support for global options that get passed to sub-commands
@ 2013-08-31 10:34 Jani Nikula
2013-08-31 10:34 ` [RFC PATCH 2/2] cli: use global verbose, debug, and no-hooks options in notmuch new Jani Nikula
0 siblings, 1 reply; 2+ messages in thread
From: Jani Nikula @ 2013-08-31 10:34 UTC (permalink / raw)
To: notmuch
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [RFC PATCH 2/2] cli: use global verbose, debug, and no-hooks options in notmuch new
2013-08-31 10:34 [RFC PATCH 1/2] cli: add support for global options that get passed to sub-commands Jani Nikula
@ 2013-08-31 10:34 ` Jani Nikula
0 siblings, 0 replies; 2+ messages in thread
From: Jani Nikula @ 2013-08-31 10:34 UTC (permalink / raw)
To: notmuch
Deprecate the old notmuch new options, but keep them around for a
transitional period, overriding the top level options.
---
notmuch-new.c | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/notmuch-new.c b/notmuch-new.c
index faa33f1..d425103 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -855,16 +855,21 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
int opt_index;
int i;
notmuch_bool_t timer_is_active = FALSE;
- notmuch_bool_t no_hooks = FALSE;
+ notmuch_bool_t no_hooks = notmuch_global_get_no_hooks (config);
- add_files_state.verbose = FALSE;
- add_files_state.debug = FALSE;
+ add_files_state.verbose = notmuch_global_get_verbose (config);
+ add_files_state.debug = notmuch_global_get_debug (config);
add_files_state.output_is_a_tty = isatty (fileno (stdout));
+ /* transitional, these will go away */
+ notmuch_bool_t deprecated_verbose = FALSE;
+ notmuch_bool_t deprecated_debug = FALSE;
+ notmuch_bool_t deprecated_no_hooks = FALSE;
+
notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_BOOLEAN, &add_files_state.verbose, "verbose", 'v', 0 },
- { NOTMUCH_OPT_BOOLEAN, &add_files_state.debug, "debug", 'd', 0 },
- { NOTMUCH_OPT_BOOLEAN, &no_hooks, "no-hooks", 'n', 0 },
+ { NOTMUCH_OPT_BOOLEAN, &deprecated_verbose, "verbose", 'v', 0 },
+ { NOTMUCH_OPT_BOOLEAN, &deprecated_debug, "debug", 'd', 0 },
+ { NOTMUCH_OPT_BOOLEAN, &deprecated_no_hooks, "no-hooks", 'n', 0 },
{ 0, 0, 0, 0, 0 }
};
@@ -874,6 +879,20 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
return 1;
}
+ /* transitional, these will go away */
+ if (deprecated_verbose) {
+ add_files_state.verbose = deprecated_verbose;
+ fprintf (stderr, "Note: 'notmuch new --verbose' is deprecated. Please use 'notmuch --verbose new' instead.\n");
+ }
+ if (deprecated_debug) {
+ add_files_state.debug = deprecated_debug;
+ fprintf (stderr, "Note: 'notmuch new --debug' is deprecated. Please use 'notmuch --debug new' instead.\n");
+ }
+ if (deprecated_no_hooks) {
+ no_hooks = deprecated_no_hooks;
+ fprintf (stderr, "Note: 'notmuch new --no-hooks' is deprecated. Please use 'notmuch --no-hooks new' instead.\n");
+ }
+
add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);
add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-09-01 6:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-31 10:34 [RFC PATCH 1/2] cli: add support for global options that get passed to sub-commands Jani Nikula
2013-08-31 10:34 ` [RFC PATCH 2/2] cli: use global verbose, debug, and no-hooks options in notmuch new Jani Nikula
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).