diff options
| author | David Bremner <david@tethera.net> | 2021-01-02 13:10:39 -0400 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2021-02-06 19:52:11 -0400 |
| commit | 0d3bef312dd624225825e6fe175ea8830c1c9e39 (patch) | |
| tree | 3c9fdf207c504eec56f47e98ca3851b15f119307 /notmuch.c | |
| parent | 5ef731f1aa0aa3d8fc89d1e724c021dbed8d4418 (diff) | |
cli/new: convert to new config framework
In addition to the same type of changes as converting other
subcommands, add the possibility of creating a database at the top
level. It would probably make sense to use this for insert as well.
Diffstat (limited to 'notmuch.c')
| -rw-r--r-- | notmuch.c | 50 |
1 files changed, 38 insertions, 12 deletions
@@ -143,7 +143,8 @@ static command_t commands[] = { "Notmuch main command." }, { "setup", notmuch_setup_command, NOTMUCH_COMMAND_CONFIG_OPEN | NOTMUCH_COMMAND_CONFIG_CREATE, "Interactively set up notmuch for first use." }, - { "new", notmuch_new_command, NOTMUCH_COMMAND_CONFIG_OPEN, + { "new", notmuch_new_command, + NOTMUCH_COMMAND_DATABASE_EARLY | NOTMUCH_COMMAND_DATABASE_WRITE | NOTMUCH_COMMAND_DATABASE_CREATE, "Find and import new messages to the notmuch database." }, { "insert", notmuch_insert_command, NOTMUCH_COMMAND_DATABASE_EARLY | NOTMUCH_COMMAND_DATABASE_WRITE, "Add a new message into the maildir and notmuch database." }, @@ -504,23 +505,48 @@ main (int argc, char *argv[]) if (command->mode & NOTMUCH_COMMAND_DATABASE_EARLY) { char *status_string = NULL; notmuch_database_mode_t mode; - if (command->mode & NOTMUCH_COMMAND_DATABASE_WRITE) + notmuch_status_t status; + + if (command->mode & NOTMUCH_COMMAND_DATABASE_WRITE || + command->mode & NOTMUCH_COMMAND_DATABASE_CREATE) mode = NOTMUCH_DATABASE_MODE_READ_WRITE; else mode = NOTMUCH_DATABASE_MODE_READ_ONLY; - if (notmuch_database_open_with_config (NULL, - mode, - config_file_name, - NULL, - ¬much, - &status_string)) { - if (status_string) { - fputs (status_string, stderr); - free (status_string); + if (command->mode & NOTMUCH_COMMAND_DATABASE_CREATE) { + status = notmuch_database_create_with_config (NULL, + config_file_name, + NULL, + ¬much, + &status_string); + if (status && status != NOTMUCH_STATUS_DATABASE_EXISTS) { + if (status_string) { + fputs (status_string, stderr); + free (status_string); + } + + if (status == NOTMUCH_STATUS_NO_CONFIG) + fputs ("Try running 'notmuch setup' to create a configuration.", stderr); + + return EXIT_FAILURE; } + } - return EXIT_FAILURE; + if (notmuch == NULL) { + status = notmuch_database_open_with_config (NULL, + mode, + config_file_name, + NULL, + ¬much, + &status_string); + if (status) { + if (status_string) { + fputs (status_string, stderr); + free (status_string); + } + + return EXIT_FAILURE; + } } } else { config = notmuch_config_open (local, config_file_name, command->mode); |
