unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#45004] [PATCH shepherd] herd: Suggest alternatives when action and service are likely swapped.
@ 2020-12-02  9:21 Leo Prikler
  2020-12-02 20:03 ` Jonathan Brielmaier
  2023-06-02 14:04 ` bug#45004: [PATCH shepherd] herd: Suggest alternatives when action and service are likely swapped Ludovic Courtès
  0 siblings, 2 replies; 6+ messages in thread
From: Leo Prikler @ 2020-12-02  9:21 UTC (permalink / raw)
  To: 45004

* modules/shepherd/script/herd.scm (run-command)[reply error]: Report a more
descriptive error if service could reasonably have been an action.
---
 modules/shepherd/scripts/herd.scm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/modules/shepherd/scripts/herd.scm b/modules/shepherd/scripts/herd.scm
index 106de1e..a178f51 100644
--- a/modules/shepherd/scripts/herd.scm
+++ b/modules/shepherd/scripts/herd.scm
@@ -179,6 +179,15 @@ the daemon via SOCKET-FILE."
                 ('messages messages))
         (for-each display-line messages)
         (report-command-error error)
+        (match (list action service)
+          ((_ (or 'start 'stop 'status 'doc))
+           (report-error (l10n "did you mean 'herd ~a ~a'?")
+                         service action))
+          ((root (or 'help 'halt 'power-off 'load 'eval 'unload 'reload
+                     'daemonize 'persistency 'no-persistency 'cd 'restart))
+           (report-error (l10n "did you mean 'herd ~a ~a'?")
+                         service action))
+          ((_ _) *unspecified*))
         (exit 1))
        ((? eof-object?)
         ;; When stopping shepherd, we may get an EOF in lieu of a real reply,
-- 
2.29.2





^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [bug#45004] [PATCH shepherd] herd: Suggest alternatives when action and service are likely swapped.
  2020-12-02  9:21 [bug#45004] [PATCH shepherd] herd: Suggest alternatives when action and service are likely swapped Leo Prikler
@ 2020-12-02 20:03 ` Jonathan Brielmaier
  2020-12-04 17:18   ` Oleg Pykhalov
  2023-06-02 14:04 ` bug#45004: [PATCH shepherd] herd: Suggest alternatives when action and service are likely swapped Ludovic Courtès
  1 sibling, 1 reply; 6+ messages in thread
From: Jonathan Brielmaier @ 2020-12-02 20:03 UTC (permalink / raw)
  To: 45004

On 02.12.20 10:21, Leo Prikler wrote:
> * modules/shepherd/script/herd.scm (run-command)[reply error]: Report a more
> descriptive error if service could reasonably have been an action.

I didn't test it, but it sounds like a good idea :)

It reminds me that I should maybe write bash completions files for
shepherd as it annoys me pretty hard ^^




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [bug#45004] [PATCH shepherd] herd: Suggest alternatives when action and service are likely swapped.
  2020-12-02 20:03 ` Jonathan Brielmaier
@ 2020-12-04 17:18   ` Oleg Pykhalov
  2023-06-02 13:56     ` [bug#45004] Bash completion for ‘herd’ Ludovic Courtès
  0 siblings, 1 reply; 6+ messages in thread
From: Oleg Pykhalov @ 2020-12-04 17:18 UTC (permalink / raw)
  To: Jonathan Brielmaier; +Cc: 45004


[-- Attachment #1.1: Type: text/plain, Size: 343 bytes --]

Jonathan Brielmaier <jonathan.brielmaier@web.de> writes:

[…]

> It reminds me that I should maybe write bash completions files for
> shepherd as it annoys me pretty hard ^^

You could take my, which probably should be improved before merging to
Shepherd IMHO, e.g. avoid 'awk'.

~/.local/share/bash-completion/completions/herd


[-- Attachment #1.2: herd completion --]
[-- Type: text/plain, Size: 980 bytes --]

_herd_complete_service(){
    local command="${COMP_WORDS[1]}"
    local services="$(sudo herd status | awk '/*/ || /^ +/ || /^ -/ { print $NF }' | sort -u)"
    COMPREPLY=($(compgen -W "$services" -- "${COMP_WORDS[$COMP_CWORD]}"))
}

_herd_is_command ()
{
    local word
    local result="false"
    for word in ${COMP_WORDS[*]}t
    do
	if [ "$word" = "$1" ]
	then
	    result=true
	    break
	fi
    done
    $result
}

_herd_complete()
{
    local word_count=${#COMP_WORDS[*]}
    local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
    case $COMP_CWORD in
        1)
	    if [ -z "$_herd_subcommands" ]
	    then
		# Cache the list of subcommands to speed things up.
		_herd_subcommands="enable disable start status stop"
	    fi
            COMPREPLY=($(compgen -W "$_herd_subcommands" -- "${COMP_WORDS[$COMP_CWORD]}"))
            ;;
        *)
            case $COMP_CWORD in
		2) _herd_complete_service;;
	    esac
            ;;
    esac
}

complete -F _herd_complete herd

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [bug#45004] Bash completion for ‘herd’
  2020-12-04 17:18   ` Oleg Pykhalov
@ 2023-06-02 13:56     ` Ludovic Courtès
  2023-06-02 22:23       ` Oleg Pykhalov
  0 siblings, 1 reply; 6+ messages in thread
From: Ludovic Courtès @ 2023-06-02 13:56 UTC (permalink / raw)
  To: Oleg Pykhalov; +Cc: 45004, Jonathan Brielmaier

Hi Oleg,

Oleg Pykhalov <go.wigust@gmail.com> skribis:

> You could take my, which probably should be improved before merging to
> Shepherd IMHO, e.g. avoid 'awk'.
>
> ~/.local/share/bash-completion/completions/herd
>
> _herd_complete_service(){
>     local command="${COMP_WORDS[1]}"
>     local services="$(sudo herd status | awk '/*/ || /^ +/ || /^ -/ { print $NF }' | sort -u)"
>     COMPREPLY=($(compgen -W "$services" -- "${COMP_WORDS[$COMP_CWORD]}"))
> }
>
> _herd_is_command ()
> {
>     local word
>     local result="false"
>     for word in ${COMP_WORDS[*]}t
>     do
> 	if [ "$word" = "$1" ]
> 	then
> 	    result=true
> 	    break
> 	fi
>     done
>     $result
> }
>
> _herd_complete()
> {
>     local word_count=${#COMP_WORDS[*]}
>     local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
>     case $COMP_CWORD in
>         1)
> 	    if [ -z "$_herd_subcommands" ]
> 	    then
> 		# Cache the list of subcommands to speed things up.
> 		_herd_subcommands="enable disable start status stop"
> 	    fi
>             COMPREPLY=($(compgen -W "$_herd_subcommands" -- "${COMP_WORDS[$COMP_CWORD]}"))
>             ;;
>         *)
>             case $COMP_CWORD in
> 		2) _herd_complete_service;;
> 	    esac
>             ;;
>     esac
> }
>
> complete -F _herd_complete herd

Would you mind polishing a bit (as you see fit; perhaps use grep/sed
rather than Awk?) and submitting a patch for this?  I’d be happy to
apply it!

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#45004: [PATCH shepherd] herd: Suggest alternatives when action and service are likely swapped.
  2020-12-02  9:21 [bug#45004] [PATCH shepherd] herd: Suggest alternatives when action and service are likely swapped Leo Prikler
  2020-12-02 20:03 ` Jonathan Brielmaier
@ 2023-06-02 14:04 ` Ludovic Courtès
  1 sibling, 0 replies; 6+ messages in thread
From: Ludovic Courtès @ 2023-06-02 14:04 UTC (permalink / raw)
  To: Liliana Marie Prikler; +Cc: 45004-done

Hey Liliana,

> * modules/shepherd/script/herd.scm (run-command)[reply error]: Report a more
> descriptive error if service could reasonably have been an action.

I found this old patch of yours, which I find very useful.  So… finally
applied as Shepherd commit b9b15db9e5bda27287706b6727c462df686e7621!

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [bug#45004] Bash completion for ‘herd’
  2023-06-02 13:56     ` [bug#45004] Bash completion for ‘herd’ Ludovic Courtès
@ 2023-06-02 22:23       ` Oleg Pykhalov
  0 siblings, 0 replies; 6+ messages in thread
From: Oleg Pykhalov @ 2023-06-02 22:23 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 45004, Jonathan Brielmaier

[-- Attachment #1: Type: text/plain, Size: 283 bytes --]

Hi Ludovic,

Ludovic Courtès <ludo@gnu.org> writes:

[…]

> Would you mind polishing a bit (as you see fit; perhaps use grep/sed
> rather than Awk?) and submitting a patch for this?  I’d be happy to
> apply it!

Done. Please check the 63860 issue.

Regards,
Oleg.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-06-02 22:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02  9:21 [bug#45004] [PATCH shepherd] herd: Suggest alternatives when action and service are likely swapped Leo Prikler
2020-12-02 20:03 ` Jonathan Brielmaier
2020-12-04 17:18   ` Oleg Pykhalov
2023-06-02 13:56     ` [bug#45004] Bash completion for ‘herd’ Ludovic Courtès
2023-06-02 22:23       ` Oleg Pykhalov
2023-06-02 14:04 ` bug#45004: [PATCH shepherd] herd: Suggest alternatives when action and service are likely swapped Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.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).