aboutsummaryrefslogtreecommitdiffhomepage
path: root/notmuch.c
diff options
context:
space:
mode:
authorGravatar Austin Clements <amdragon@MIT.EDU>2012-12-15 22:17:23 -0500
committerGravatar David Bremner <bremner@debian.org>2012-12-16 17:20:33 -0400
commit1c6195b9e35e511e115f94b45d97aa58ee41b307 (patch)
treeb51eed0180afeb9d78523436841262a9f2795492 /notmuch.c
parent1e12b91b3cf823d21f7edf8c0f1c687df56fec14 (diff)
cli: Framework for structured output versioning
Currently there is a period of pain whenever we make backward-incompatible changes to the structured output format, which discourages not only backward-incompatible improvements to the format, but also backwards-compatible additions that may not be "perfect". In the end, these problems limit experimentation and innovation. This series of patches introduces a way for CLI callers to request a specific format version on the command line and to determine if the CLI does not supported the requested version (and perhaps present a useful diagnostic to the user). Since the caller requests a format version, it's also possible for the CLI to support multiple incompatible versions simultaneously, unlike the alternate approach of including version information in the output. This patch lays the groundwork by introducing a versioning convention, standard exit codes, and a utility function to check the requested version and produce standardized diagnostic messages and exit statuses.
Diffstat (limited to 'notmuch.c')
-rw-r--r--notmuch.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/notmuch.c b/notmuch.c
index 4ff66e30..9516dfb7 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -82,6 +82,8 @@ static command_t commands[] = {
"This message, or more detailed help for the named command." }
};
+int notmuch_format_version;
+
static void
usage (FILE *out)
{
@@ -109,6 +111,33 @@ usage (FILE *out)
"and \"notmuch help search-terms\" for the common search-terms syntax.\n\n");
}
+void
+notmuch_exit_if_unsupported_format (void)
+{
+ if (notmuch_format_version > NOTMUCH_FORMAT_CUR) {
+ fprintf (stderr, "\
+A caller requested output format version %d, but the installed notmuch\n\
+CLI only supports up to format version %d. You may need to upgrade your\n\
+notmuch CLI.\n",
+ notmuch_format_version, NOTMUCH_FORMAT_CUR);
+ exit (NOTMUCH_EXIT_FORMAT_TOO_NEW);
+ } else if (notmuch_format_version < NOTMUCH_FORMAT_MIN) {
+ fprintf (stderr, "\
+A caller requested output format version %d, which is no longer supported\n\
+by the notmuch CLI (it requires at least version %d). You may need to\n\
+upgrade your notmuch front-end.\n",
+ notmuch_format_version, NOTMUCH_FORMAT_MIN);
+ exit (NOTMUCH_EXIT_FORMAT_TOO_OLD);
+ } else if (notmuch_format_version != NOTMUCH_FORMAT_CUR) {
+ /* Warn about old version requests so compatibility issues are
+ * less likely when we drop support for a deprecated format
+ * versions. */
+ fprintf (stderr, "\
+A caller requested deprecated output format version %d, which may not\n\
+be supported in the future.\n", notmuch_format_version);
+ }
+}
+
static void
exec_man (const char *page)
{
@@ -242,6 +271,9 @@ main (int argc, char *argv[])
g_mime_init (0);
g_type_init ();
+ /* Globally default to the current output format version. */
+ notmuch_format_version = NOTMUCH_FORMAT_CUR;
+
if (argc == 1)
return notmuch (local);