From 380da0c1a1db1ed2a3c311f2170e3b762dfb624e Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Wed, 8 Jul 2020 00:30:11 +0100 Subject: [PATCH] dovecot-auth-cli: Add help message The dovecot-auth-cli binary can be useful to debug and troubleshoot dovecot auth issues. This patch adds a small help message to make it easier for users to understand how to use it. --- cmd/dovecot-auth-cli/dovecot-auth-cli.go | 23 +++++++++++++++++++-- cmd/dovecot-auth-cli/test_wrong_command.cmy | 4 ++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cmd/dovecot-auth-cli/dovecot-auth-cli.go b/cmd/dovecot-auth-cli/dovecot-auth-cli.go index 67ee5a4..10248ec 100644 --- a/cmd/dovecot-auth-cli/dovecot-auth-cli.go +++ b/cmd/dovecot-auth-cli/dovecot-auth-cli.go @@ -8,12 +8,31 @@ package main import ( "flag" "fmt" + "os" "blitiri.com.ar/go/chasquid/internal/dovecot" ) +const help = ` +Usage: + dovecot-auth-cli exists user@domain + dovecot-auth-cli auth user@domain password + +Example: + dovecot-auth-cli /var/run/dovecot/auth-chasquid exists user@domain + dovecot-auth-cli /var/run/dovecot/auth-chasquid auth user@domain password + +` + func main() { flag.Parse() + + if len(flag.Args()) < 3 { + fmt.Fprint(os.Stderr, help) + fmt.Print("no: invalid arguments\n") + return + } + a := dovecot.NewAuth(flag.Arg(0)+"-userdb", flag.Arg(0)+"-client") var ok bool @@ -25,11 +44,11 @@ func main() { case "auth": ok, err = a.Authenticate(flag.Arg(2), flag.Arg(3)) default: - fmt.Printf("unknown subcommand\n") + err = fmt.Errorf("unknown subcommand %q", flag.Arg(1)) } if ok { - fmt.Printf("yes\n") + fmt.Print("yes\n") return } diff --git a/cmd/dovecot-auth-cli/test_wrong_command.cmy b/cmd/dovecot-auth-cli/test_wrong_command.cmy index afcd774..ec558e0 100644 --- a/cmd/dovecot-auth-cli/test_wrong_command.cmy +++ b/cmd/dovecot-auth-cli/test_wrong_command.cmy @@ -1,4 +1,4 @@ -c = ./dovecot-auth-cli .missingsocket something -c <- unknown subcommand +c = ./dovecot-auth-cli .missingsocket something else +c <- no: unknown subcommand "something" c wait 0