-
-command_t commands[] = {
- { "setup", setup_command,
- "Interactively setup notmuch for first use.\n\n"
- "\t\tInvoking notmuch with no command argument will run setup if\n"
- "\t\tthe setup command has not previously been completed." },
- { "new", new_command,
- "Find and import any new messages.\n\n"
- "\t\tScans all sub-directories of the database, adding new messages\n"
- "\t\tthat are found. Each new message will be tagges as both\n"
- "\t\t\"inbox\" and \"unread\".\n"
- "\n"
- "\t\tNote: \"notmuch new\" will skip any read-only directories,\n"
- "\t\tso you can use that to mark tdirectories that will not\n"
- "\t\treceive any new mail (and make \"notmuch new\" faster)." },
- { "search", search_command,
- "<search-term> [...]\n\n"
- "\t\tSearch for threads matching the given search terms.\n"
- "\t\tOnce we actually implement search we'll document the\n"
- "\t\tsyntax here." },
- { "show", show_command,
- "<thread-id>\n\n"
- "\t\tShow the thread with the given thread ID (see 'search')." },
- { "tag", tag_command,
- "+<tag>|-<tag> [...] [--] <search-term> [...]\n\n"
- "\t\tAdd or remove the specified tags to all messages matching\n"
- "\t\tthe specified search terms. The search terms are handled\n"
- "\t\texactly as in 'search' so one can use that command first\n"
- "\t\tto see what will be modified.\n\n"
- "\t\tTags prefixed by '+' are added while those prefixed by '-' are\n"
- "\t\tremoved. For each message, tag removal is before tag addition.\n\n"
- "\t\tThe beginning of <search-terms> is recognized by the first\n"
- "\t\targument that begins with neither '+' nor '-'. Support for\n"
- "\t\tan initial search term beginning with '+' or '-' is provided\n"
- "\t\tby allowing the user to specify a \"--\" argument to separate\n"
- "\t\tthe tags from the search terms." },
- { "dump", dump_command,
- "[<filename>]\n\n"
- "\t\tCreate a plain-text dump of the tags for each message\n"
- "\t\twriting to the given filename, if any, or to stdout.\n"
- "\t\tThese tags are the only data in the notmuch database\n"
- "\t\tthat can't be recreated from the messages themselves.\n"
- "\t\tThe output of notmuch dump is therefore the only\n"
- "\t\tcritical thing to backup (and much more friendly to\n"
- "\t\tincremental backup than the native database files." },
- { "restore", restore_command,
- "<filename>\n\n"
- "\t\tRestore the tags from the given dump file (see 'dump')." }
-};
-
-static void
-usage (void)
-{
- command_t *command;
- unsigned int i;
-
- fprintf (stderr, "Usage: notmuch <command> [args...]\n");
- fprintf (stderr, "\n");
- fprintf (stderr, "Where <command> and [args...] are as follows:\n");
- fprintf (stderr, "\n");
-
- for (i = 0; i < ARRAY_SIZE (commands); i++) {
- command = &commands[i];
-
- fprintf (stderr, "\t%s\t%s\n\n", command->name, command->usage);
- }
-}
-
-int
-main (int argc, char *argv[])
-{
- command_t *command;
- unsigned int i;
-
- if (argc == 1)
- return setup_command (0, NULL);
-
- for (i = 0; i < ARRAY_SIZE (commands); i++) {
- command = &commands[i];
-
- if (strcmp (argv[1], command->name) == 0)
- return (command->function) (argc - 2, &argv[2]);
- }
-
- /* Don't complain about "help" being an unknown command when we're
- about to provide exactly what's wanted anyway. */
- if (strcmp (argv[1], "help") == 0 ||
- strcmp (argv[1], "--help") == 0)
- {
- fprintf (stderr, "The notmuch mail system.\n\n");
- usage ();
- return 0;
- } else {
- fprintf (stderr, "Error: Unknown command '%s'\n\n", argv[1]);
- usage ();
- return 1;
- }
-}