From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/2] cli: convert "notmuch new" to the argument parser
Date: Mon, 3 Dec 2012 22:56:13 +0200 [thread overview]
Message-ID: <e31ac6b2ceed533f8ac5386a010f4c052e09502e.1354568072.git.jani@nikula.org> (raw)
In-Reply-To: <c4f2a1048763950dd14e13c99a4e7eb333be8c9d.1354568072.git.jani@nikula.org>
In-Reply-To: <c4f2a1048763950dd14e13c99a4e7eb333be8c9d.1354568072.git.jani@nikula.org>
Use the notmuch argument parser to handle arguments in "notmuch
new". As a side effect, this fixes broken STRNCMP_LITERAL usage that
accepts, for example, --verbosefoo for --verbose.
---
notmuch-new.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/notmuch-new.c b/notmuch-new.c
index 718a538..feb9c32 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -36,8 +36,8 @@ typedef struct _filename_list {
typedef struct {
int output_is_a_tty;
- int verbose;
- int debug;
+ notmuch_bool_t verbose;
+ notmuch_bool_t debug;
const char **new_tags;
size_t new_tags_length;
const char **new_ignore;
@@ -853,28 +853,28 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
char *dot_notmuch_path;
struct sigaction action;
_filename_node_t *f;
+ int opt_index;
int i;
notmuch_bool_t timer_is_active = FALSE;
- notmuch_bool_t run_hooks = TRUE;
+ notmuch_bool_t no_hooks = FALSE;
- add_files_state.verbose = 0;
- add_files_state.debug = 0;
+ add_files_state.verbose = FALSE;
+ add_files_state.debug = FALSE;
add_files_state.output_is_a_tty = isatty (fileno (stdout));
- argc--; argv++; /* skip subcommand argument */
+ 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 },
+ { 0, 0, 0, 0, 0 }
+ };
- for (i = 0; i < argc && argv[i][0] == '-'; i++) {
- if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {
- add_files_state.verbose = 1;
- } else if (strcmp (argv[i], "--debug") == 0) {
- add_files_state.debug = 1;
- } else if (strcmp (argv[i], "--no-hooks") == 0) {
- run_hooks = FALSE;
- } else {
- fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
- return 1;
- }
+ opt_index = parse_arguments (argc, argv, options, 1);
+ if (opt_index < 0) {
+ /* diagnostics already printed */
+ return 1;
}
+
config = notmuch_config_open (ctx, NULL, NULL);
if (config == NULL)
return 1;
@@ -884,7 +884,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
db_path = notmuch_config_get_database_path (config);
- if (run_hooks) {
+ if (!no_hooks) {
ret = notmuch_run_hook (db_path, "pre-new");
if (ret)
return ret;
@@ -1045,7 +1045,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
notmuch_database_destroy (notmuch);
- if (run_hooks && !ret && !interrupted)
+ if (!no_hooks && !ret && !interrupted)
ret = notmuch_run_hook (db_path, "post-new");
return ret || interrupted;
--
1.7.10.4
next prev parent reply other threads:[~2012-12-03 20:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-03 20:56 [PATCH 1/2] cli: fix notmuch top level argument parsing Jani Nikula
2012-12-03 20:56 ` Jani Nikula [this message]
2012-12-03 22:28 ` [PATCH 2/2] cli: convert "notmuch new" to the argument parser Austin Clements
2012-12-03 22:35 ` Jani Nikula
2012-12-03 21:32 ` [PATCH 1/2] cli: fix notmuch top level argument parsing Michal Nazarewicz
2012-12-03 22:17 ` Jani Nikula
2012-12-03 22:30 ` Jani Nikula
2012-12-04 14:00 ` Michal Nazarewicz
2012-12-04 13:16 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e31ac6b2ceed533f8ac5386a010f4c052e09502e.1354568072.git.jani@nikula.org \
--to=jani@nikula.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).