This allows specifying config file as a top level argument to notmuch,
and generally makes it possible to override config file options in
main(), without having to touch the subcommands.
If the config file does not exist, one will be created for the notmuch
main command and setup and help subcommands. Help is special in this
regard; the config is created just to avoid errors about missing
config, but it will not be saved.
This also makes notmuch config the talloc context for subcommands.
12 files changed:
*/
extern int notmuch_format_version;
*/
extern int notmuch_format_version;
+typedef struct _notmuch_config notmuch_config_t;
+
/* Commands that support structured output should support the
* following argument
* { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 }
/* Commands that support structured output should support the
* following argument
* { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 }
notmuch_crypto_cleanup (notmuch_crypto_t *crypto);
int
notmuch_crypto_cleanup (notmuch_crypto_t *crypto);
int
-notmuch_count_command (void *ctx, int argc, char *argv[]);
-
-int
-notmuch_dump_command (void *ctx, int argc, char *argv[]);
+notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]);
-notmuch_new_command (void *ctx, int argc, char *argv[]);
+notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]);
-notmuch_reply_command (void *ctx, int argc, char *argv[]);
+notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]);
-notmuch_restore_command (void *ctx, int argc, char *argv[]);
+notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]);
-notmuch_search_command (void *ctx, int argc, char *argv[]);
+notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]);
-notmuch_setup_command (void *ctx, int argc, char *argv[]);
+notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]);
-notmuch_show_command (void *ctx, int argc, char *argv[]);
+notmuch_setup_command (notmuch_config_t *config, int argc, char *argv[]);
-notmuch_tag_command (void *ctx, int argc, char *argv[]);
+notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]);
-notmuch_search_tags_command (void *ctx, int argc, char *argv[]);
+notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]);
-notmuch_cat_command (void *ctx, int argc, char *argv[]);
-
-int
-notmuch_config_command (void *ctx, int argc, char *argv[]);
+notmuch_config_command (notmuch_config_t *config, int argc, char *argv[]);
const char *
notmuch_time_relative_date (const void *ctx, time_t then);
const char *
notmuch_time_relative_date (const void *ctx, time_t then);
-typedef struct _notmuch_config notmuch_config_t;
-
notmuch_config_t *
notmuch_config_open (void *ctx,
const char *filename,
notmuch_config_t *
notmuch_config_open (void *ctx,
const char *filename,
-notmuch_config_command_get (void *ctx, char *item)
+notmuch_config_command_get (notmuch_config_t *config, char *item)
- notmuch_config_t *config;
-
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
if (strcmp(item, "database.path") == 0) {
printf ("%s\n", notmuch_config_get_database_path (config));
} else if (strcmp(item, "user.name") == 0) {
if (strcmp(item, "database.path") == 0) {
printf ("%s\n", notmuch_config_get_database_path (config));
} else if (strcmp(item, "user.name") == 0) {
- notmuch_config_close (config);
-
-notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[])
+notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char *argv[])
- notmuch_config_t *config;
if (_item_split (item, &group, &key))
return 1;
if (_item_split (item, &group, &key))
return 1;
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
/* With only the name of an item, we clear it from the
* configuration file.
*
/* With only the name of an item, we clear it from the
* configuration file.
*
- ret = notmuch_config_save (config);
- notmuch_config_close (config);
-
- return ret;
+ return notmuch_config_save (config);
-notmuch_config_command_list (void *ctx)
+notmuch_config_command_list (notmuch_config_t *config)
- notmuch_config_t *config;
char **groups;
size_t g, groups_length;
char **groups;
size_t g, groups_length;
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
groups = g_key_file_get_groups (config->key_file, &groups_length);
if (groups == NULL)
return 1;
groups = g_key_file_get_groups (config->key_file, &groups_length);
if (groups == NULL)
return 1;
- notmuch_config_close (config);
-
-notmuch_config_command (void *ctx, int argc, char *argv[])
+notmuch_config_command (notmuch_config_t *config, int argc, char *argv[])
{
argc--; argv++; /* skip subcommand argument */
{
argc--; argv++; /* skip subcommand argument */
"one argument.\n");
return 1;
}
"one argument.\n");
return 1;
}
- return notmuch_config_command_get (ctx, argv[1]);
+ return notmuch_config_command_get (config, argv[1]);
} else if (strcmp (argv[0], "set") == 0) {
if (argc < 2) {
fprintf (stderr, "Error: notmuch config set requires at least "
"one argument.\n");
return 1;
}
} else if (strcmp (argv[0], "set") == 0) {
if (argc < 2) {
fprintf (stderr, "Error: notmuch config set requires at least "
"one argument.\n");
return 1;
}
- return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2);
+ return notmuch_config_command_set (config, argv[1], argc - 2, argv + 2);
} else if (strcmp (argv[0], "list") == 0) {
} else if (strcmp (argv[0], "list") == 0) {
- return notmuch_config_command_list (ctx);
+ return notmuch_config_command_list (config);
}
fprintf (stderr, "Unrecognized argument for notmuch config: %s\n",
}
fprintf (stderr, "Unrecognized argument for notmuch config: %s\n",
-notmuch_count_command (void *ctx, int argc, char *argv[])
+notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
- notmuch_config_t *config;
notmuch_database_t *notmuch;
notmuch_query_t *query;
char *query_str;
notmuch_database_t *notmuch;
notmuch_query_t *query;
char *query_str;
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
if (notmuch_database_open (notmuch_config_get_database_path (config),
NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
return 1;
if (notmuch_database_open (notmuch_config_get_database_path (config),
NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
return 1;
- query_str = query_string_from_args (ctx, argc-opt_index, argv+opt_index);
+ query_str = query_string_from_args (config, argc-opt_index, argv+opt_index);
if (query_str == NULL) {
fprintf (stderr, "Out of memory.\n");
return 1;
}
if (*query_str == '\0') {
if (query_str == NULL) {
fprintf (stderr, "Out of memory.\n");
return 1;
}
if (*query_str == '\0') {
- query_str = talloc_strdup (ctx, "");
+ query_str = talloc_strdup (config, "");
}
query = notmuch_query_create (notmuch, query_str);
}
query = notmuch_query_create (notmuch, query_str);
#include "string-util.h"
int
#include "string-util.h"
int
-notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
+notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
- notmuch_config_t *config;
notmuch_database_t *notmuch;
notmuch_query_t *query;
FILE *output = stdout;
notmuch_database_t *notmuch;
notmuch_query_t *query;
FILE *output = stdout;
notmuch_tags_t *tags;
const char *query_str = "";
notmuch_tags_t *tags;
const char *query_str = "";
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
if (notmuch_database_open (notmuch_config_get_database_path (config),
NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
return 1;
if (notmuch_database_open (notmuch_config_get_database_path (config),
NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
return 1;
-notmuch_new_command (void *ctx, int argc, char *argv[])
+notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
- notmuch_config_t *config;
notmuch_database_t *notmuch;
add_files_state_t add_files_state;
double elapsed;
notmuch_database_t *notmuch;
add_files_state_t add_files_state;
double elapsed;
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
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);
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);
- dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
+ dot_notmuch_path = talloc_asprintf (config, "%s/%s", db_path, ".notmuch");
if (stat (dot_notmuch_path, &st)) {
int count;
if (stat (dot_notmuch_path, &st)) {
int count;
add_files_state.removed_messages = add_files_state.renamed_messages = 0;
gettimeofday (&add_files_state.tv_start, NULL);
add_files_state.removed_messages = add_files_state.renamed_messages = 0;
gettimeofday (&add_files_state.tv_start, NULL);
- add_files_state.removed_files = _filename_list_create (ctx);
- add_files_state.removed_directories = _filename_list_create (ctx);
- add_files_state.directory_mtimes = _filename_list_create (ctx);
+ add_files_state.removed_files = _filename_list_create (config);
+ add_files_state.removed_directories = _filename_list_create (config);
+ add_files_state.directory_mtimes = _filename_list_create (config);
if (! debugger_is_active () && add_files_state.output_is_a_tty
&& ! add_files_state.verbose) {
if (! debugger_is_active () && add_files_state.output_is_a_tty
&& ! add_files_state.verbose) {
gettimeofday (&tv_start, NULL);
for (f = add_files_state.removed_directories->head, i = 0; f && !interrupted; f = f->next, i++) {
gettimeofday (&tv_start, NULL);
for (f = add_files_state.removed_directories->head, i = 0; f && !interrupted; f = f->next, i++) {
- ret = _remove_directory (ctx, notmuch, f->filename, &add_files_state);
+ ret = _remove_directory (config, notmuch, f->filename, &add_files_state);
if (ret)
goto DONE;
if (do_print_progress) {
if (ret)
goto DONE;
if (do_print_progress) {
-notmuch_reply_command (void *ctx, int argc, char *argv[])
+notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
- notmuch_config_t *config;
notmuch_database_t *notmuch;
notmuch_query_t *query;
char *query_string;
notmuch_database_t *notmuch;
notmuch_query_t *query;
char *query_string;
reply_format_func = notmuch_reply_format_headers_only;
} else if (format == FORMAT_JSON) {
reply_format_func = notmuch_reply_format_sprinter;
reply_format_func = notmuch_reply_format_headers_only;
} else if (format == FORMAT_JSON) {
reply_format_func = notmuch_reply_format_sprinter;
- sp = sprinter_json_create (ctx, stdout);
+ sp = sprinter_json_create (config, stdout);
} else if (format == FORMAT_SEXP) {
reply_format_func = notmuch_reply_format_sprinter;
} else if (format == FORMAT_SEXP) {
reply_format_func = notmuch_reply_format_sprinter;
- sp = sprinter_sexp_create (ctx, stdout);
+ sp = sprinter_sexp_create (config, stdout);
} else {
reply_format_func = notmuch_reply_format_default;
}
notmuch_exit_if_unsupported_format ();
} else {
reply_format_func = notmuch_reply_format_default;
}
notmuch_exit_if_unsupported_format ();
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
- query_string = query_string_from_args (ctx, argc-opt_index, argv+opt_index);
+ query_string = query_string_from_args (config, argc-opt_index, argv+opt_index);
if (query_string == NULL) {
fprintf (stderr, "Out of memory\n");
return 1;
if (query_string == NULL) {
fprintf (stderr, "Out of memory\n");
return 1;
- if (reply_format_func (ctx, config, query, ¶ms, reply_all, sp) != 0)
+ if (reply_format_func (config, config, query, ¶ms, reply_all, sp) != 0)
return 1;
notmuch_crypto_cleanup (¶ms.crypto);
return 1;
notmuch_crypto_cleanup (¶ms.crypto);
-notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
+notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
- notmuch_config_t *config;
notmuch_database_t *notmuch;
notmuch_bool_t accumulate = FALSE;
tag_op_flag_t flags = 0;
notmuch_database_t *notmuch;
notmuch_bool_t accumulate = FALSE;
tag_op_flag_t flags = 0;
int opt_index;
int input_format = DUMP_FORMAT_AUTO;
int opt_index;
int input_format = DUMP_FORMAT_AUTO;
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
if (notmuch_database_open (notmuch_config_get_database_path (config),
NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
return 1;
if (notmuch_database_open (notmuch_config_get_database_path (config),
NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
return 1;
- tag_ops = tag_op_list_create (ctx);
+ tag_ops = tag_op_list_create (config);
if (tag_ops == NULL) {
fprintf (stderr, "Out of memory.\n");
return 1;
if (tag_ops == NULL) {
fprintf (stderr, "Out of memory.\n");
return 1;
if (line_ctx != NULL)
talloc_free (line_ctx);
if (line_ctx != NULL)
talloc_free (line_ctx);
- line_ctx = talloc_new (ctx);
+ line_ctx = talloc_new (config);
if (input_format == DUMP_FORMAT_SUP) {
ret = parse_sup_line (line_ctx, line, &query_string, tag_ops);
} else {
if (input_format == DUMP_FORMAT_SUP) {
ret = parse_sup_line (line_ctx, line, &query_string, tag_ops);
} else {
-notmuch_search_command (void *ctx, int argc, char *argv[])
+notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
- notmuch_config_t *config;
notmuch_database_t *notmuch;
notmuch_query_t *query;
char *query_str;
notmuch_database_t *notmuch;
notmuch_query_t *query;
char *query_str;
switch (format_sel) {
case NOTMUCH_FORMAT_TEXT:
switch (format_sel) {
case NOTMUCH_FORMAT_TEXT:
- format = sprinter_text_create (ctx, stdout);
+ format = sprinter_text_create (config, stdout);
break;
case NOTMUCH_FORMAT_TEXT0:
if (output == OUTPUT_SUMMARY) {
fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");
return 1;
}
break;
case NOTMUCH_FORMAT_TEXT0:
if (output == OUTPUT_SUMMARY) {
fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");
return 1;
}
- format = sprinter_text0_create (ctx, stdout);
+ format = sprinter_text0_create (config, stdout);
break;
case NOTMUCH_FORMAT_JSON:
break;
case NOTMUCH_FORMAT_JSON:
- format = sprinter_json_create (ctx, stdout);
+ format = sprinter_json_create (config, stdout);
break;
case NOTMUCH_FORMAT_SEXP:
break;
case NOTMUCH_FORMAT_SEXP:
- format = sprinter_sexp_create (ctx, stdout);
+ format = sprinter_sexp_create (config, stdout);
break;
default:
/* this should never happen */
break;
default:
/* this should never happen */
notmuch_exit_if_unsupported_format ();
notmuch_exit_if_unsupported_format ();
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
if (notmuch_database_open (notmuch_config_get_database_path (config),
NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
return 1;
if (notmuch_database_open (notmuch_config_get_database_path (config),
NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
return 1;
-notmuch_setup_command (unused (void *ctx),
+notmuch_setup_command (notmuch_config_t *config,
unused (int argc), unused (char *argv[]))
{
char *response = NULL;
size_t response_size = 0;
unused (int argc), unused (char *argv[]))
{
char *response = NULL;
size_t response_size = 0;
- notmuch_config_t *config;
const char **old_other_emails;
size_t old_other_emails_len;
GPtrArray *other_emails;
const char **old_other_emails;
size_t old_other_emails_len;
GPtrArray *other_emails;
chomp_newline (response); \
} while (0)
chomp_newline (response); \
} while (0)
- config = notmuch_config_open (ctx, NULL, TRUE);
-
if (notmuch_config_is_new (config))
welcome_message_pre_setup ();
if (notmuch_config_is_new (config))
welcome_message_pre_setup ();
for (i = 0; i < old_other_emails_len; i++) {
prompt ("Additional email address [%s]: ", old_other_emails[i]);
if (strlen (response))
for (i = 0; i < old_other_emails_len; i++) {
prompt ("Additional email address [%s]: ", old_other_emails[i]);
if (strlen (response))
- g_ptr_array_add (other_emails, talloc_strdup (ctx, response));
+ g_ptr_array_add (other_emails, talloc_strdup (config, response));
- g_ptr_array_add (other_emails, talloc_strdup (ctx,
+ g_ptr_array_add (other_emails, talloc_strdup (config,
old_other_emails[i]));
}
do {
prompt ("Additional email address [Press 'Enter' if none]: ");
if (strlen (response))
old_other_emails[i]));
}
do {
prompt ("Additional email address [Press 'Enter' if none]: ");
if (strlen (response))
- g_ptr_array_add (other_emails, talloc_strdup (ctx, response));
+ g_ptr_array_add (other_emails, talloc_strdup (config, response));
} while (strlen (response));
if (other_emails->len)
notmuch_config_set_user_other_email (config,
} while (strlen (response));
if (other_emails->len)
notmuch_config_set_user_other_email (config,
if (strlen (response)) {
const char *absolute_path;
if (strlen (response)) {
const char *absolute_path;
- absolute_path = make_path_absolute (ctx, response);
+ absolute_path = make_path_absolute (config, response);
notmuch_config_set_database_path (config, absolute_path);
}
notmuch_config_set_database_path (config, absolute_path);
}
prompt ("]: ");
if (strlen (response)) {
prompt ("]: ");
if (strlen (response)) {
- GPtrArray *tags = parse_tag_list (ctx, response);
+ GPtrArray *tags = parse_tag_list (config, response);
notmuch_config_set_new_tags (config, (const char **) tags->pdata,
tags->len);
notmuch_config_set_new_tags (config, (const char **) tags->pdata,
tags->len);
prompt ("]: ");
if (strlen (response)) {
prompt ("]: ");
if (strlen (response)) {
- GPtrArray *tags = parse_tag_list (ctx, response);
+ GPtrArray *tags = parse_tag_list (config, response);
notmuch_config_set_search_exclude_tags (config,
(const char **) tags->pdata,
notmuch_config_set_search_exclude_tags (config,
(const char **) tags->pdata,
-notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
+notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
- notmuch_config_t *config;
notmuch_database_t *notmuch;
notmuch_query_t *query;
char *query_string;
notmuch_database_t *notmuch;
notmuch_query_t *query;
char *query_string;
else
params.entire_thread = FALSE;
else
params.entire_thread = FALSE;
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
- query_string = query_string_from_args (ctx, argc-opt_index, argv+opt_index);
+ query_string = query_string_from_args (config, argc-opt_index, argv+opt_index);
if (query_string == NULL) {
fprintf (stderr, "Out of memory\n");
return 1;
if (query_string == NULL) {
fprintf (stderr, "Out of memory\n");
return 1;
}
/* Create structure printer. */
}
/* Create structure printer. */
- sprinter = format->new_sprinter(ctx, stdout);
+ sprinter = format->new_sprinter(config, stdout);
/* If a single message is requested we do not use search_excludes. */
if (params.part >= 0)
/* If a single message is requested we do not use search_excludes. */
if (params.part >= 0)
- ret = do_show_single (ctx, query, format, sprinter, ¶ms);
+ ret = do_show_single (config, query, format, sprinter, ¶ms);
else {
/* We always apply set the exclude flag. The
* exclude=true|false option controls whether or not we return
else {
/* We always apply set the exclude flag. The
* exclude=true|false option controls whether or not we return
params.omit_excluded = FALSE;
}
params.omit_excluded = FALSE;
}
- ret = do_show (ctx, query, format, sprinter, ¶ms);
+ ret = do_show (config, query, format, sprinter, ¶ms);
}
notmuch_crypto_cleanup (¶ms.crypto);
}
notmuch_crypto_cleanup (¶ms.crypto);
-notmuch_tag_command (void *ctx, int argc, char *argv[])
+notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])
{
tag_op_list_t *tag_ops = NULL;
char *query_string = NULL;
{
tag_op_list_t *tag_ops = NULL;
char *query_string = NULL;
- notmuch_config_t *config;
notmuch_database_t *notmuch;
struct sigaction action;
tag_op_flag_t tag_flags = TAG_FLAG_NONE;
notmuch_database_t *notmuch;
struct sigaction action;
tag_op_flag_t tag_flags = TAG_FLAG_NONE;
- tag_ops = tag_op_list_create (ctx);
+ tag_ops = tag_op_list_create (config);
if (tag_ops == NULL) {
fprintf (stderr, "Out of memory.\n");
return 1;
}
if (tag_ops == NULL) {
fprintf (stderr, "Out of memory.\n");
return 1;
}
- if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index,
+ if (parse_tag_command_line (config, argc - opt_index, argv + opt_index,
&query_string, tag_ops))
return 1;
}
&query_string, tag_ops))
return 1;
}
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
if (notmuch_database_open (notmuch_config_get_database_path (config),
NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
return 1;
if (notmuch_database_open (notmuch_config_get_database_path (config),
NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
return 1;
tag_flags |= TAG_FLAG_MAILDIR_SYNC;
if (batch)
tag_flags |= TAG_FLAG_MAILDIR_SYNC;
if (batch)
- ret = tag_file (ctx, notmuch, tag_flags, input);
+ ret = tag_file (config, notmuch, tag_flags, input);
- ret = tag_query (ctx, notmuch, query_string, tag_ops, tag_flags);
+ ret = tag_query (config, notmuch, query_string, tag_ops, tag_flags);
notmuch_database_destroy (notmuch);
notmuch_database_destroy (notmuch);
#include "notmuch-client.h"
#include "notmuch-client.h"
-typedef int (*command_function_t) (void *ctx, int argc, char *argv[]);
+typedef int (*command_function_t) (notmuch_config_t *config, int argc, char *argv[]);
typedef struct command {
const char *name;
command_function_t function;
typedef struct command {
const char *name;
command_function_t function;
+ notmuch_bool_t create_config;
const char *arguments;
const char *summary;
} command_t;
static int
const char *arguments;
const char *summary;
} command_t;
static int
-notmuch_help_command (void *ctx, int argc, char *argv[]);
+notmuch_help_command (notmuch_config_t *config, int argc, char *argv[]);
-notmuch_command (void *ctx, int argc, char *argv[]);
+notmuch_command (notmuch_config_t *config, int argc, char *argv[]);
static command_t commands[] = {
static command_t commands[] = {
- { NULL, notmuch_command,
+ { NULL, notmuch_command, TRUE,
NULL,
"Notmuch main command." },
NULL,
"Notmuch main command." },
- { "setup", notmuch_setup_command,
+ { "setup", notmuch_setup_command, TRUE,
NULL,
"Interactively setup notmuch for first use." },
NULL,
"Interactively setup notmuch for first use." },
- { "new", notmuch_new_command,
+ { "new", notmuch_new_command, FALSE,
"[options...]",
"Find and import new messages to the notmuch database." },
"[options...]",
"Find and import new messages to the notmuch database." },
- { "search", notmuch_search_command,
+ { "search", notmuch_search_command, FALSE,
"[options...] <search-terms> [...]",
"Search for messages matching the given search terms." },
"[options...] <search-terms> [...]",
"Search for messages matching the given search terms." },
- { "show", notmuch_show_command,
+ { "show", notmuch_show_command, FALSE,
"<search-terms> [...]",
"Show all messages matching the search terms." },
"<search-terms> [...]",
"Show all messages matching the search terms." },
- { "count", notmuch_count_command,
+ { "count", notmuch_count_command, FALSE,
"[options...] <search-terms> [...]",
"Count messages matching the search terms." },
"[options...] <search-terms> [...]",
"Count messages matching the search terms." },
- { "reply", notmuch_reply_command,
+ { "reply", notmuch_reply_command, FALSE,
"[options...] <search-terms> [...]",
"Construct a reply template for a set of messages." },
"[options...] <search-terms> [...]",
"Construct a reply template for a set of messages." },
- { "tag", notmuch_tag_command,
+ { "tag", notmuch_tag_command, FALSE,
"+<tag>|-<tag> [...] [--] <search-terms> [...]" ,
"Add/remove tags for all messages matching the search terms." },
"+<tag>|-<tag> [...] [--] <search-terms> [...]" ,
"Add/remove tags for all messages matching the search terms." },
- { "dump", notmuch_dump_command,
+ { "dump", notmuch_dump_command, FALSE,
"[<filename>] [--] [<search-terms>]",
"Create a plain-text dump of the tags for each message." },
"[<filename>] [--] [<search-terms>]",
"Create a plain-text dump of the tags for each message." },
- { "restore", notmuch_restore_command,
+ { "restore", notmuch_restore_command, FALSE,
"[--accumulate] [<filename>]",
"Restore the tags from the given dump file (see 'dump')." },
"[--accumulate] [<filename>]",
"Restore the tags from the given dump file (see 'dump')." },
- { "config", notmuch_config_command,
+ { "config", notmuch_config_command, FALSE,
"[get|set] <section>.<item> [value ...]",
"Get or set settings in the notmuch configuration file." },
"[get|set] <section>.<item> [value ...]",
"Get or set settings in the notmuch configuration file." },
- { "help", notmuch_help_command,
+ { "help", notmuch_help_command, TRUE, /* create but don't save config */
"[<command>]",
"This message, or more detailed help for the named command." }
};
"[<command>]",
"This message, or more detailed help for the named command." }
};
-notmuch_help_command (void *ctx, int argc, char *argv[])
+notmuch_help_command (notmuch_config_t *config, int argc, char *argv[])
command = find_command (argv[0]);
if (command) {
command = find_command (argv[0]);
if (command) {
- char *page = talloc_asprintf (ctx, "notmuch-%s", command->name);
+ char *page = talloc_asprintf (config, "notmuch-%s", command->name);
* to be more clever about this in the future.
*/
static int
* to be more clever about this in the future.
*/
static int
-notmuch_command (void *ctx, unused(int argc), unused(char *argv[]))
+notmuch_command (notmuch_config_t *config,
+ unused(int argc), unused(char *argv[]))
- notmuch_config_t *config;
char *db_path;
struct stat st;
char *db_path;
struct stat st;
- config = notmuch_config_open (ctx, NULL, TRUE);
-
/* If the user has never configured notmuch, then run
* notmuch_setup_command which will give a nice welcome message,
* and interactively guide the user through the configuration. */
/* If the user has never configured notmuch, then run
* notmuch_setup_command which will give a nice welcome message,
* and interactively guide the user through the configuration. */
- if (notmuch_config_is_new (config)) {
- notmuch_config_close (config);
- return notmuch_setup_command (ctx, 0, NULL);
- }
+ if (notmuch_config_is_new (config))
+ return notmuch_setup_command (config, 0, NULL);
/* Notmuch is already configured, but is there a database? */
/* Notmuch is already configured, but is there a database? */
- db_path = talloc_asprintf (ctx, "%s/%s",
+ db_path = talloc_asprintf (config, "%s/%s",
notmuch_config_get_database_path (config),
".notmuch");
if (stat (db_path, &st)) {
notmuch_config_get_database_path (config),
".notmuch");
if (stat (db_path, &st)) {
- notmuch_config_close (config);
if (errno != ENOENT) {
fprintf (stderr, "Error looking for notmuch database at %s: %s\n",
db_path, strerror (errno));
if (errno != ENOENT) {
fprintf (stderr, "Error looking for notmuch database at %s: %s\n",
db_path, strerror (errno));
notmuch_config_get_user_name (config),
notmuch_config_get_user_primary_email (config));
notmuch_config_get_user_name (config),
notmuch_config_get_user_primary_email (config));
- notmuch_config_close (config);
-
char *talloc_report;
const char *command_name = NULL;
command_t *command;
char *talloc_report;
const char *command_name = NULL;
command_t *command;
+ notmuch_config_t *config;
notmuch_bool_t print_help=FALSE, print_version=FALSE;
int opt_index;
int ret = 0;
notmuch_bool_t print_help=FALSE, print_version=FALSE;
int opt_index;
int ret = 0;
- ret = (command->function)(local, argc - opt_index, argv + opt_index);
+ config = notmuch_config_open (local, NULL, command->create_config);
+ if (!config)
+ return 1;
+
+ ret = (command->function)(config, argc - opt_index, argv + opt_index);
+
+ notmuch_config_close (config);
talloc_report = getenv ("NOTMUCH_TALLOC_REPORT");
if (talloc_report && strcmp (talloc_report, "") != 0) {
talloc_report = getenv ("NOTMUCH_TALLOC_REPORT");
if (talloc_report && strcmp (talloc_report, "") != 0) {