[PATCH shepherd] herd: Suggest alternatives when action and service are likely swapped.

  • Done
  • quality assurance status badge
Details
4 participants
  • Oleg Pykhalov
  • Jonathan Brielmaier
  • Leo Prikler
  • Ludovic Courtès
Owner
unassigned
Submitted by
Leo Prikler
Severity
normal
L
L
Leo Prikler wrote on 2 Dec 2020 10:21
(address . guix-patches@gnu.org)
20201202092106.22770-1-leo.prikler@student.tugraz.at
* 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(+)

Toggle diff (22 lines)
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
J
J
Jonathan Brielmaier wrote on 2 Dec 2020 21:03
(address . guix-patches@gnu.org)
c7c5ce55-a080-91c6-d29c-bbc0aa181492@web.de
On 02.12.20 10:21, Leo Prikler wrote:
Toggle quote (3 lines)
> * 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 ^^
O
O
Oleg Pykhalov wrote on 4 Dec 2020 18:18
(name . Jonathan Brielmaier)(address . jonathan.brielmaier@web.de)(address . 45004@debbugs.gnu.org)
87a6utqyku.fsf@gmail.com
Jonathan Brielmaier <jonathan.brielmaier@web.de> writes:

[…]

Toggle quote (3 lines)
> 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
_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
-----BEGIN PGP SIGNATURE-----

iQJIBAEBCgAyFiEEcjhxI46s62NFSFhXFn+OpQAa+pwFAl/Kb3IUHGdvLndpZ3Vz
dEBnbWFpbC5jb20ACgkQFn+OpQAa+pyufhAAhJce5fa8tK3aO/dzrXaD7pu4B6Ig
59gSYTIjPOojLT2r7WqOeBLwIw1opQrRdKF9p5b5vxrnaAcB8amJobzNKTyVSP3f
uHvAelAU/bv3BUHobOpZA+VxQJkK928pQRi2IKsvCh87GZ31PdevxOTWCkb74VRP
p4azpvdz7vsO4sAq6KJPGo+Mfpo2U4BWxFgif9yPP3Gv9dVEYcHCL/3i1rtuUdvB
PK/iFUvKoxzZLd/hMRtUvfPiyc+l57Mlhb8P0gIiWF7/dmLtVx+X85hTrMx8r71Z
VRODRxEz5aOM3uQbWYyV4PzqTWfJueWuxj81AYhPFHAeQSyrbeDng+wM1cg1nDI5
JTMkEBr4kdOLw58EdSa+JE6M2erLHG4WTnbbIaAXAKdVKOdgSwq0hP1CEqsnKfVs
qaP2OO9+UciB4DaqPr+dS1B1gbUGMW0q4dLylQoYuNAi7YWbHFBCPCDCK0YUfH1E
QYBnk7wDdNaGus3LBj4/1geqjUHzfziUjvt7FLlPd9kPLlfEuJgAoPM+nVm+DkJS
XlDT3L9VpmOBLQTZWYemXTqi6wpf6HJKl3vR/vDU/BrokpZjgpPBcnbGlnQ/UlwM
ziUC36KNh6lG6D6IPDtwzg/zTv/HKAnyHc+feYjaZFGijMDUYPDJ6UUGoFgJV/ii
UWmoxzacE2YrUcU=
=MTyf
-----END PGP SIGNATURE-----

L
L
Ludovic Courtès wrote on 2 Jun 2023 15:56
Bash completion for ‘herd’
(name . Oleg Pykhalov)(address . go.wigust@gmail.com)
87h6rq55ok.fsf_-_@gnu.org
Hi Oleg,

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

Toggle quote (49 lines)
> 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’.
L
L
Ludovic Courtès wrote on 2 Jun 2023 16:04
Re: bug#45004: [PATCH shepherd] herd: Suggest alternatives when action and service are likely swapped.
(name . Liliana Marie Prikler)(address . liliana.prikler@gmail.com)(address . 45004-done@debbugs.gnu.org)
87cz2e55a9.fsf@gnu.org
Hey Liliana,

Toggle quote (3 lines)
> * 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’.
Closed
O
O
Oleg Pykhalov wrote on 3 Jun 2023 00:23
Re: Bash completion for ‘herd’
(name . Ludovic Courtès)(address . ludo@gnu.org)
878rd1cxlv.fsf@gmail.com
Hi Ludovic,

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

[…]

Toggle quote (4 lines)
> 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.
-----BEGIN PGP SIGNATURE-----

iQJIBAEBCgAyFiEEcjhxI46s62NFSFhXFn+OpQAa+pwFAmR6a9wUHGdvLndpZ3Vz
dEBnbWFpbC5jb20ACgkQFn+OpQAa+pzRbhAAzCboz1zZGiEU47SgHQvClEG9BARb
lDLI3ntXB7rTecuOf0owxB/7AYgf8MwAevPf2mzJERJ4tw0K9nEhPF7Y59o37jsQ
AwthEF60H3pjXFsELdfs4p9t+Vw8WdoBVXfcCEUTmPvP3Nesw4F8l2YLhJXgSSqI
JK0ojxd8eJlhmjkmCFib7XT1so5h2RHn7FaIGB4LthYAsNcEfSJyF9I448NBZFQw
rfyybWBnX12gT4oV6tGd7vv+2Xk2caxJ2LVBdOESa5bHRh71FwFljXa4KVPyqIKs
s8okTl81L9G31jOYOEXGA8/KCQc8km7pME1pH2bulg/uswQQbFlE+6RNvci/NJUL
o+4P3jtBXW6xyPFa1DVVo/ctljChx4hyOgPkAgTeQgfiAtooa5Z5uyUXeMU6ty/j
PFSe7M6K1O/msbfEUyBtnht65tAWej/OEQDGxpW9k7LXK4bnmQiWY7KfigIMmZ4z
mwnZAbtWQQcYddKGjMiMa1NYAHEQpaMOYEI7aGOwfROel2avToWvyeD+Nf4Eu+oG
m70EMG2REJchZR33WejBU1U2D79w+QzygaynCv2Rezr63O10QQnrPeUe6GRjDv3a
ycWaYMa+9fz7fowiUUmnEt+mytbxM/1y+3Z8FWHny/7PqQMHJpRAK1LGx/9yaDKO
fsDVr2pcF0y82Zo=
=AFc0
-----END PGP SIGNATURE-----

?