[PATCH] cli: Be more helpful when .notmuch-config does not exist

2014-09-07 Thread David Bremner
Austin Clements  writes:

>
> Since this condition is expected for new users, this patch adds
> specific handling for the file-not-found case to give a message that
> is friendly and actionable.

pushed

d


Re: [PATCH] cli: Be more helpful when .notmuch-config does not exist

2014-09-07 Thread David Bremner
Austin Clements amdra...@mit.edu writes:


 Since this condition is expected for new users, this patch adds
 specific handling for the file-not-found case to give a message that
 is friendly and actionable.

pushed

d
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] cli: Be more helpful when .notmuch-config does not exist

2014-09-03 Thread Austin Clements
Previously, if the user ran any subcommand that required a
configuration (e.g., notmuch new) but didn't have a configuration,
notmuch would give the rather un-friendly and un-actionable message

  Error reading configuration file .notmuch-config: No such file or directory

Since this condition is expected for new users, this patch adds
specific handling for the file-not-found case to give a message that
is friendly and actionable.
---
 notmuch-config.c   | 26 --
 test/T040-setup.sh |  6 ++
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/notmuch-config.c b/notmuch-config.c
index db487db..a564bca 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -283,16 +283,22 @@ notmuch_config_open (void *ctx,
 G_KEY_FILE_KEEP_COMMENTS,
 ))
 {
-   /* If create_new is true, then the caller is prepared for a
-* default configuration file in the case of FILE NOT
-* FOUND. Otherwise, any read failure is an error.
-*/
-   if (create_new &&
-   error->domain == G_FILE_ERROR &&
-   error->code == G_FILE_ERROR_NOENT)
-   {
-   g_error_free (error);
-   config->is_new = TRUE;
+   if (error->domain == G_FILE_ERROR && error->code == G_FILE_ERROR_NOENT) 
{
+   /* If create_new is true, then the caller is prepared for a
+* default configuration file in the case of FILE NOT
+* FOUND.
+*/
+   if (create_new) {
+   g_error_free (error);
+   config->is_new = TRUE;
+   } else {
+   fprintf (stderr, "Configuration file %s not found.\n"
+"Try running 'notmuch setup' to create a 
configuration.\n",
+config->filename);
+   talloc_free (config);
+   g_error_free (error);
+   return NULL;
+   }
}
else
{
diff --git a/test/T040-setup.sh b/test/T040-setup.sh
index 124ef1c..b1972e7 100755
--- a/test/T040-setup.sh
+++ b/test/T040-setup.sh
@@ -3,6 +3,12 @@
 test_description='"notmuch setup"'
 . ./test-lib.sh

+test_begin_subtest "Notmuch new without a config suggests notmuch setup"
+output=$(notmuch --config=new-notmuch-config new 2>&1)
+test_expect_equal "$output" "\
+Configuration file new-notmuch-config not found.
+Try running 'notmuch setup' to create a configuration."
+
 test_begin_subtest "Create a new config interactively"
 notmuch --config=new-notmuch-config > /dev/null <

[PATCH] cli: Be more helpful when .notmuch-config does not exist

2014-09-03 Thread Austin Clements
Previously, if the user ran any subcommand that required a
configuration (e.g., notmuch new) but didn't have a configuration,
notmuch would give the rather un-friendly and un-actionable message

  Error reading configuration file .notmuch-config: No such file or directory

Since this condition is expected for new users, this patch adds
specific handling for the file-not-found case to give a message that
is friendly and actionable.
---
 notmuch-config.c   | 26 --
 test/T040-setup.sh |  6 ++
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/notmuch-config.c b/notmuch-config.c
index db487db..a564bca 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -283,16 +283,22 @@ notmuch_config_open (void *ctx,
 G_KEY_FILE_KEEP_COMMENTS,
 error))
 {
-   /* If create_new is true, then the caller is prepared for a
-* default configuration file in the case of FILE NOT
-* FOUND. Otherwise, any read failure is an error.
-*/
-   if (create_new 
-   error-domain == G_FILE_ERROR 
-   error-code == G_FILE_ERROR_NOENT)
-   {
-   g_error_free (error);
-   config-is_new = TRUE;
+   if (error-domain == G_FILE_ERROR  error-code == G_FILE_ERROR_NOENT) 
{
+   /* If create_new is true, then the caller is prepared for a
+* default configuration file in the case of FILE NOT
+* FOUND.
+*/
+   if (create_new) {
+   g_error_free (error);
+   config-is_new = TRUE;
+   } else {
+   fprintf (stderr, Configuration file %s not found.\n
+Try running 'notmuch setup' to create a 
configuration.\n,
+config-filename);
+   talloc_free (config);
+   g_error_free (error);
+   return NULL;
+   }
}
else
{
diff --git a/test/T040-setup.sh b/test/T040-setup.sh
index 124ef1c..b1972e7 100755
--- a/test/T040-setup.sh
+++ b/test/T040-setup.sh
@@ -3,6 +3,12 @@
 test_description='notmuch setup'
 . ./test-lib.sh
 
+test_begin_subtest Notmuch new without a config suggests notmuch setup
+output=$(notmuch --config=new-notmuch-config new 21)
+test_expect_equal $output \
+Configuration file new-notmuch-config not found.
+Try running 'notmuch setup' to create a configuration.
+
 test_begin_subtest Create a new config interactively
 notmuch --config=new-notmuch-config  /dev/null EOF
 Test Suite
-- 
2.1.0

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] cli: Be more helpful when .notmuch-config does not exist

2014-09-03 Thread Carl Worth
Austin Clements amdra...@mit.edu writes:
 Since this condition is expected for new users, this patch adds
 specific handling for the file-not-found case to give a message that
 is friendly and actionable.
...
 + fprintf (stderr, Configuration file %s not found.\n
 +  Try running 'notmuch setup' to create a 
 configuration.\n,
 +  config-filename);

Thanks, Austin!

I've always wanted notmuch to provide as gentle an introduction as
possible, (since switching MUA and indexing all email[*] is already a
fairly invasive thing).

So I really appreciate improvements like this.

 +test_begin_subtest Notmuch new without a config suggests notmuch setup
 +output=$(notmuch --config=new-notmuch-config new 21)
 +test_expect_equal $output \
 +Configuration file new-notmuch-config not found.
 +Try running 'notmuch setup' to create a configuration.

And a test to boot. That really warms my heart.

-Carl

[*] A further possible improvement here would be some mechanism for
initially indexing only very recent email, (to let the user start
playing with notmuch right away), and then in some sort of ''offline''
fashion, completing the full indexing.


pgpf52pf6_z_w.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch