* [PATCH] cli: try to run external notmuch- prefixed commands as subcommands
@ 2016-10-22 12:50 Jani Nikula
2016-10-22 16:24 ` [PATCH] completion: complete notmuch emacs-mua Jani Nikula
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Jani Nikula @ 2016-10-22 12:50 UTC (permalink / raw)
To: notmuch
If the given subcommand is not known to notmuch, try to execute
external notmuch-<subcommand> instead. This allows users to have their
own notmuch related tools be run via the notmuch command, not unlike
git does. Also notmuch-emacs-mua will be executable via 'notmuch
emacs-mua'.
By design, this does not allow notmuch's own subcommands to be
overriden using external commands.
---
Whether internal subcommands can be overridden or not is up to debate,
can be consider either a bug or a feature depending on how you look at
it.
---
notmuch.c | 39 +++++++++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
diff --git a/notmuch.c b/notmuch.c
index 38b73c1d2acc..b9c320329dd5 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -363,6 +363,39 @@ notmuch_command (notmuch_config_t *config,
return EXIT_SUCCESS;
}
+/*
+ * Try to run subcommand in argv[0] as notmuch- prefixed external
+ * command. argv must be NULL terminated (argv passed to main always
+ * is).
+ *
+ * Does not return if the external command is found and
+ * executed. Return TRUE if external command is not found. Return
+ * FALSE on errors.
+ */
+static notmuch_bool_t try_external_command(char *argv[])
+{
+ char *old_argv0 = argv[0];
+ notmuch_bool_t ret = TRUE;
+
+ argv[0] = talloc_asprintf (NULL, "notmuch-%s", old_argv0);
+
+ /*
+ * This will only return on errors. Not finding an external
+ * command (ENOENT) is not an error from our perspective.
+ */
+ execvp (argv[0], argv);
+ if (errno != ENOENT) {
+ fprintf (stderr, "Error: Running external command '%s' failed: %s\n",
+ argv[0], strerror(errno));
+ ret = FALSE;
+ }
+
+ talloc_free (argv[0]);
+ argv[0] = old_argv0;
+
+ return ret;
+}
+
int
main (int argc, char *argv[])
{
@@ -406,8 +439,10 @@ main (int argc, char *argv[])
command = find_command (command_name);
if (!command) {
- fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
- command_name);
+ /* This won't return if the external command is found. */
+ if (try_external_command(argv + opt_index))
+ fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
+ command_name);
ret = EXIT_FAILURE;
goto DONE;
}
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH] completion: complete notmuch emacs-mua
2016-10-22 12:50 [PATCH] cli: try to run external notmuch- prefixed commands as subcommands Jani Nikula
@ 2016-10-22 16:24 ` Jani Nikula
2016-10-22 16:32 ` [PATCH] man: advertize notmuch-emacs-mua as notmuch emacs-mua subcommand Jani Nikula
2016-10-23 3:22 ` [PATCH] cli: try to run external notmuch- prefixed commands as subcommands Mark Walters
2016-10-31 11:18 ` David Bremner
2 siblings, 1 reply; 8+ messages in thread
From: Jani Nikula @ 2016-10-22 16:24 UTC (permalink / raw)
To: notmuch
With subcommand handling for external commands we can easily complete
'notmuch emacs-mua' using the existing completion system.
---
completion/notmuch-completion.bash | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
index 78047b5f424d..9e1f7bb74bbf 100644
--- a/completion/notmuch-completion.bash
+++ b/completion/notmuch-completion.bash
@@ -204,6 +204,38 @@ _notmuch_dump()
esac
}
+_notmuch_emacs_mua()
+{
+ local cur prev words cword split
+ _init_completion -s || return
+
+ $split &&
+ case "${prev}" in
+ --to|--cc|--bcc)
+ COMPREPLY=( $(compgen -W "`_notmuch_email to:${cur}`" -- ${cur}) )
+ return
+ ;;
+ --body)
+ _filedir
+ return
+ ;;
+ esac
+
+ ! $split &&
+ case "${cur}" in
+ -*)
+ local options="--subject= --to= --cc= --bcc= --body= --no-window-system --client --auto-daemon --create-frame --print --help"
+
+ compopt -o nospace
+ COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
+ ;;
+ *)
+ COMPREPLY=( $(compgen -W "`_notmuch_email to:${cur}`" -- ${cur}) )
+ return
+ ;;
+ esac
+}
+
_notmuch_insert()
{
local cur prev words cword split
@@ -464,7 +496,7 @@ _notmuch_tag()
_notmuch()
{
- local _notmuch_commands="compact config count dump help insert new reply restore search address setup show tag"
+ local _notmuch_commands="compact config count dump help insert new reply restore search address setup show tag emacs-mua"
local arg cur prev words cword split
# require bash-completion with _init_completion
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH] man: advertize notmuch-emacs-mua as notmuch emacs-mua subcommand
2016-10-22 16:24 ` [PATCH] completion: complete notmuch emacs-mua Jani Nikula
@ 2016-10-22 16:32 ` Jani Nikula
2016-11-02 10:42 ` David Bremner
0 siblings, 1 reply; 8+ messages in thread
From: Jani Nikula @ 2016-10-22 16:32 UTC (permalink / raw)
To: notmuch
With subcommand handling for external commands we can now hide the
implementation detail of emacs-mua being a separate notmuch-emacs-mua
script.
---
doc/man1/notmuch-emacs-mua.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/doc/man1/notmuch-emacs-mua.rst b/doc/man1/notmuch-emacs-mua.rst
index 7c5729047173..f0148b8e5340 100644
--- a/doc/man1/notmuch-emacs-mua.rst
+++ b/doc/man1/notmuch-emacs-mua.rst
@@ -5,7 +5,7 @@ notmuch-emacs-mua
SYNOPSIS
========
-**notmuch-emacs-mua** [options ...] [<to-address> ...]
+**notmuch** **emacs-mua** [options ...] [<to-address> ...]
DESCRIPTION
===========
@@ -13,7 +13,7 @@ DESCRIPTION
Start composing an email in the Notmuch Emacs UI with the specified
subject, recipients, and message body.
-Supported options for **notmuch-emacs-mua** include
+Supported options for **emacs-mua** include
``-h, --help``
Display help.
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] man: advertize notmuch-emacs-mua as notmuch emacs-mua subcommand
2016-10-22 16:32 ` [PATCH] man: advertize notmuch-emacs-mua as notmuch emacs-mua subcommand Jani Nikula
@ 2016-11-02 10:42 ` David Bremner
2016-11-02 18:41 ` Jani Nikula
0 siblings, 1 reply; 8+ messages in thread
From: David Bremner @ 2016-11-02 10:42 UTC (permalink / raw)
To: Jani Nikula, notmuch
Jani Nikula <jani@nikula.org> writes:
> With subcommand handling for external commands we can now hide the
> implementation detail of emacs-mua being a separate notmuch-emacs-mua
> script.
> ---
> doc/man1/notmuch-emacs-mua.rst | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/doc/man1/notmuch-emacs-mua.rst b/doc/man1/notmuch-emacs-mua.rst
> index 7c5729047173..f0148b8e5340 100644
> --- a/doc/man1/notmuch-emacs-mua.rst
> +++ b/doc/man1/notmuch-emacs-mua.rst
> @@ -5,7 +5,7 @@ notmuch-emacs-mua
> SYNOPSIS
> ========
>
> -**notmuch-emacs-mua** [options ...] [<to-address> ...]
> +**notmuch** **emacs-mua** [options ...] [<to-address> ...]
>
> DESCRIPTION
> ===========
> @@ -13,7 +13,7 @@ DESCRIPTION
> Start composing an email in the Notmuch Emacs UI with the specified
> subject, recipients, and message body.
>
> -Supported options for **notmuch-emacs-mua** include
> +Supported options for **emacs-mua** include
>
> ``-h, --help``
> Display help.
this needs to be updated for the mailto handling patch, which I just merged
d
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] man: advertize notmuch-emacs-mua as notmuch emacs-mua subcommand
2016-11-02 10:42 ` David Bremner
@ 2016-11-02 18:41 ` Jani Nikula
0 siblings, 0 replies; 8+ messages in thread
From: Jani Nikula @ 2016-11-02 18:41 UTC (permalink / raw)
To: David Bremner, notmuch
On Wed, 02 Nov 2016, David Bremner <david@tethera.net> wrote:
> Jani Nikula <jani@nikula.org> writes:
>
>> With subcommand handling for external commands we can now hide the
>> implementation detail of emacs-mua being a separate notmuch-emacs-mua
>> script.
>> ---
>> doc/man1/notmuch-emacs-mua.rst | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/doc/man1/notmuch-emacs-mua.rst b/doc/man1/notmuch-emacs-mua.rst
>> index 7c5729047173..f0148b8e5340 100644
>> --- a/doc/man1/notmuch-emacs-mua.rst
>> +++ b/doc/man1/notmuch-emacs-mua.rst
>> @@ -5,7 +5,7 @@ notmuch-emacs-mua
>> SYNOPSIS
>> ========
>>
>> -**notmuch-emacs-mua** [options ...] [<to-address> ...]
>> +**notmuch** **emacs-mua** [options ...] [<to-address> ...]
>>
>> DESCRIPTION
>> ===========
>> @@ -13,7 +13,7 @@ DESCRIPTION
>> Start composing an email in the Notmuch Emacs UI with the specified
>> subject, recipients, and message body.
>>
>> -Supported options for **notmuch-emacs-mua** include
>> +Supported options for **emacs-mua** include
>>
>> ``-h, --help``
>> Display help.
>
> this needs to be updated for the mailto handling patch, which I just merged
Rebased version at id:1478111914-21927-1-git-send-email-jani@nikula.org,
the completion patch in this thread has no conflicts.
BR,
Jani.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] cli: try to run external notmuch- prefixed commands as subcommands
2016-10-22 12:50 [PATCH] cli: try to run external notmuch- prefixed commands as subcommands Jani Nikula
2016-10-22 16:24 ` [PATCH] completion: complete notmuch emacs-mua Jani Nikula
@ 2016-10-23 3:22 ` Mark Walters
2016-10-23 18:49 ` Jani Nikula
2016-10-31 11:18 ` David Bremner
2 siblings, 1 reply; 8+ messages in thread
From: Mark Walters @ 2016-10-23 3:22 UTC (permalink / raw)
To: Jani Nikula, notmuch
On Sat, 22 Oct 2016, Jani Nikula <jani@nikula.org> wrote:
> If the given subcommand is not known to notmuch, try to execute
> external notmuch-<subcommand> instead. This allows users to have their
> own notmuch related tools be run via the notmuch command, not unlike
> git does. Also notmuch-emacs-mua will be executable via 'notmuch
> emacs-mua'.
>
> By design, this does not allow notmuch's own subcommands to be
> overriden using external commands.
>
> ---
>
> Whether internal subcommands can be overridden or not is up to debate,
> can be consider either a bug or a feature depending on how you look at
> it.
This looks good to me +1 (note my C is not great, and I haven't tested
yet). It took me a while to realise that a nice feature of this was that
we can have some commands in languages other than C, like the emacs-mua
command in the next patch.
My only query is whether we are setting ourselves up to annoy people if
we add official commands later. For example if we add a notmuch delete
command then it could break a user's setup if they have a notmuch-delete
command. Would it be worth saying that we guarantee some namespace such
as local-* (so commands called notmuch-local-*) won't be touched?
Best wishes
Mark
> ---
> notmuch.c | 39 +++++++++++++++++++++++++++++++++++++--
> 1 file changed, 37 insertions(+), 2 deletions(-)
>
> diff --git a/notmuch.c b/notmuch.c
> index 38b73c1d2acc..b9c320329dd5 100644
> --- a/notmuch.c
> +++ b/notmuch.c
> @@ -363,6 +363,39 @@ notmuch_command (notmuch_config_t *config,
> return EXIT_SUCCESS;
> }
>
> +/*
> + * Try to run subcommand in argv[0] as notmuch- prefixed external
> + * command. argv must be NULL terminated (argv passed to main always
> + * is).
> + *
> + * Does not return if the external command is found and
> + * executed. Return TRUE if external command is not found. Return
> + * FALSE on errors.
> + */
> +static notmuch_bool_t try_external_command(char *argv[])
> +{
> + char *old_argv0 = argv[0];
> + notmuch_bool_t ret = TRUE;
> +
> + argv[0] = talloc_asprintf (NULL, "notmuch-%s", old_argv0);
> +
> + /*
> + * This will only return on errors. Not finding an external
> + * command (ENOENT) is not an error from our perspective.
> + */
> + execvp (argv[0], argv);
> + if (errno != ENOENT) {
> + fprintf (stderr, "Error: Running external command '%s' failed: %s\n",
> + argv[0], strerror(errno));
> + ret = FALSE;
> + }
> +
> + talloc_free (argv[0]);
> + argv[0] = old_argv0;
> +
> + return ret;
> +}
> +
> int
> main (int argc, char *argv[])
> {
> @@ -406,8 +439,10 @@ main (int argc, char *argv[])
>
> command = find_command (command_name);
> if (!command) {
> - fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
> - command_name);
> + /* This won't return if the external command is found. */
> + if (try_external_command(argv + opt_index))
> + fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
> + command_name);
> ret = EXIT_FAILURE;
> goto DONE;
> }
> --
> 2.1.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] cli: try to run external notmuch- prefixed commands as subcommands
2016-10-23 3:22 ` [PATCH] cli: try to run external notmuch- prefixed commands as subcommands Mark Walters
@ 2016-10-23 18:49 ` Jani Nikula
0 siblings, 0 replies; 8+ messages in thread
From: Jani Nikula @ 2016-10-23 18:49 UTC (permalink / raw)
To: Mark Walters, notmuch
On Sun, 23 Oct 2016, Mark Walters <markwalters1009@gmail.com> wrote:
> On Sat, 22 Oct 2016, Jani Nikula <jani@nikula.org> wrote:
>> If the given subcommand is not known to notmuch, try to execute
>> external notmuch-<subcommand> instead. This allows users to have their
>> own notmuch related tools be run via the notmuch command, not unlike
>> git does. Also notmuch-emacs-mua will be executable via 'notmuch
>> emacs-mua'.
>>
>> By design, this does not allow notmuch's own subcommands to be
>> overriden using external commands.
FWIW this is the same as in git.
>>
>> ---
>>
>> Whether internal subcommands can be overridden or not is up to debate,
>> can be consider either a bug or a feature depending on how you look at
>> it.
>
> This looks good to me +1 (note my C is not great, and I haven't tested
> yet). It took me a while to realise that a nice feature of this was that
> we can have some commands in languages other than C, like the emacs-mua
> command in the next patch.
That's mentioned right there in the commit message, you are into reading
such things. ;)
> My only query is whether we are setting ourselves up to annoy people if
> we add official commands later. For example if we add a notmuch delete
> command then it could break a user's setup if they have a notmuch-delete
> command. Would it be worth saying that we guarantee some namespace such
> as local-* (so commands called notmuch-local-*) won't be touched?
I wouldn't worry about it. I'm inclined to say that's the risk people
have to take when they add their own notmuch-stuff.
We could guarantee we don't touch some namespace, but making things
easier is part of the point here. I don't think people are going to name
their subcommands notmuch-local-stuff just to avoid potential problems
later.
BR,
Jani.
>
> Best wishes
>
> Mark
>
>
>
>
>> ---
>> notmuch.c | 39 +++++++++++++++++++++++++++++++++++++--
>> 1 file changed, 37 insertions(+), 2 deletions(-)
>>
>> diff --git a/notmuch.c b/notmuch.c
>> index 38b73c1d2acc..b9c320329dd5 100644
>> --- a/notmuch.c
>> +++ b/notmuch.c
>> @@ -363,6 +363,39 @@ notmuch_command (notmuch_config_t *config,
>> return EXIT_SUCCESS;
>> }
>>
>> +/*
>> + * Try to run subcommand in argv[0] as notmuch- prefixed external
>> + * command. argv must be NULL terminated (argv passed to main always
>> + * is).
>> + *
>> + * Does not return if the external command is found and
>> + * executed. Return TRUE if external command is not found. Return
>> + * FALSE on errors.
>> + */
>> +static notmuch_bool_t try_external_command(char *argv[])
>> +{
>> + char *old_argv0 = argv[0];
>> + notmuch_bool_t ret = TRUE;
>> +
>> + argv[0] = talloc_asprintf (NULL, "notmuch-%s", old_argv0);
>> +
>> + /*
>> + * This will only return on errors. Not finding an external
>> + * command (ENOENT) is not an error from our perspective.
>> + */
>> + execvp (argv[0], argv);
>> + if (errno != ENOENT) {
>> + fprintf (stderr, "Error: Running external command '%s' failed: %s\n",
>> + argv[0], strerror(errno));
>> + ret = FALSE;
>> + }
>> +
>> + talloc_free (argv[0]);
>> + argv[0] = old_argv0;
>> +
>> + return ret;
>> +}
>> +
>> int
>> main (int argc, char *argv[])
>> {
>> @@ -406,8 +439,10 @@ main (int argc, char *argv[])
>>
>> command = find_command (command_name);
>> if (!command) {
>> - fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
>> - command_name);
>> + /* This won't return if the external command is found. */
>> + if (try_external_command(argv + opt_index))
>> + fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
>> + command_name);
>> ret = EXIT_FAILURE;
>> goto DONE;
>> }
>> --
>> 2.1.4
>>
>> _______________________________________________
>> notmuch mailing list
>> notmuch@notmuchmail.org
>> https://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] cli: try to run external notmuch- prefixed commands as subcommands
2016-10-22 12:50 [PATCH] cli: try to run external notmuch- prefixed commands as subcommands Jani Nikula
2016-10-22 16:24 ` [PATCH] completion: complete notmuch emacs-mua Jani Nikula
2016-10-23 3:22 ` [PATCH] cli: try to run external notmuch- prefixed commands as subcommands Mark Walters
@ 2016-10-31 11:18 ` David Bremner
2 siblings, 0 replies; 8+ messages in thread
From: David Bremner @ 2016-10-31 11:18 UTC (permalink / raw)
To: Jani Nikula, notmuch
Jani Nikula <jani@nikula.org> writes:
> If the given subcommand is not known to notmuch, try to execute
> external notmuch-<subcommand> instead. This allows users to have their
> own notmuch related tools be run via the notmuch command, not unlike
> git does. Also notmuch-emacs-mua will be executable via 'notmuch
> emacs-mua'.
>
> By design, this does not allow notmuch's own subcommands to be
> overriden using external commands.
pushed to master
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-11-02 18:43 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-22 12:50 [PATCH] cli: try to run external notmuch- prefixed commands as subcommands Jani Nikula
2016-10-22 16:24 ` [PATCH] completion: complete notmuch emacs-mua Jani Nikula
2016-10-22 16:32 ` [PATCH] man: advertize notmuch-emacs-mua as notmuch emacs-mua subcommand Jani Nikula
2016-11-02 10:42 ` David Bremner
2016-11-02 18:41 ` Jani Nikula
2016-10-23 3:22 ` [PATCH] cli: try to run external notmuch- prefixed commands as subcommands Mark Walters
2016-10-23 18:49 ` Jani Nikula
2016-10-31 11:18 ` David Bremner
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).