- date = notmuch_thread_get_oldest_date (thread);
- relative_date = notmuch_time_relative_date (local, date);
-
- printf ("thread:%s %12s %s",
- notmuch_thread_get_thread_id (thread),
- relative_date,
- notmuch_thread_get_subject (thread));
-
- printf (" (");
- for (tags = notmuch_thread_get_tags (thread);
- notmuch_tags_has_more (tags);
- notmuch_tags_advance (tags))
- {
- if (! first)
- printf (" ");
- printf ("%s", notmuch_tags_get (tags));
- first = 0;
+ fputs (format->results_end, stdout);
+
+ return 0;
+}
+
+int
+notmuch_search_command (void *ctx, int argc, char *argv[])
+{
+ notmuch_config_t *config;
+ notmuch_database_t *notmuch;
+ notmuch_query_t *query;
+ char *query_str;
+ char *opt;
+ notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;
+ const search_format_t *format = &format_text;
+ int i, ret;
+ output_t output = OUTPUT_SUMMARY;
+
+ for (i = 0; i < argc && argv[i][0] == '-'; i++) {
+ if (strcmp (argv[i], "--") == 0) {
+ i++;
+ break;
+ }
+ if (STRNCMP_LITERAL (argv[i], "--sort=") == 0) {
+ opt = argv[i] + sizeof ("--sort=") - 1;
+ if (strcmp (opt, "oldest-first") == 0) {
+ sort = NOTMUCH_SORT_OLDEST_FIRST;
+ } else if (strcmp (opt, "newest-first") == 0) {
+ sort = NOTMUCH_SORT_NEWEST_FIRST;
+ } else {
+ fprintf (stderr, "Invalid value for --sort: %s\n", opt);
+ return 1;
+ }
+ } else if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {
+ opt = argv[i] + sizeof ("--format=") - 1;
+ if (strcmp (opt, "text") == 0) {
+ format = &format_text;
+ } else if (strcmp (opt, "json") == 0) {
+ format = &format_json;
+ } else {
+ fprintf (stderr, "Invalid value for --format: %s\n", opt);
+ return 1;
+ }
+ } else if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {
+ opt = argv[i] + sizeof ("--output=") - 1;
+ if (strcmp (opt, "summary") == 0) {
+ output = OUTPUT_SUMMARY;
+ } else if (strcmp (opt, "threads") == 0) {
+ output = OUTPUT_THREADS;
+ } else if (strcmp (opt, "messages") == 0) {
+ output = OUTPUT_MESSAGES;
+ } else if (strcmp (opt, "files") == 0) {
+ output = OUTPUT_FILES;
+ } else if (strcmp (opt, "tags") == 0) {
+ output = OUTPUT_TAGS;
+ } else {
+ fprintf (stderr, "Invalid value for --output: %s\n", opt);
+ return 1;
+ }
+ } else {
+ fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
+ return 1;