diff cmd/sievemgr/delete.go @ 5:4dff4c3f0fbb

Introduce configuration file where account information is specified Introduce a configuration file where account information must be specified instead of passing it with each invocation on the command line. Each account has a name by which it can be selected and one may be specified as the default account. This is intended to improve usability for productive usage. Enforce strict permissions since passwords may be specified for non-interactive usage. Remove command-line flags for passing account information.
author Guido Berhoerster <guido+sievemgr@berhoerster.name>
date Tue, 03 Nov 2020 23:44:45 +0100
parents 0cd5a454dfb4
children fc5e6970a0d5
line wrap: on
line diff
--- a/cmd/sievemgr/delete.go	Tue Oct 27 19:17:56 2020 +0100
+++ b/cmd/sievemgr/delete.go	Tue Nov 03 23:44:45 2020 +0100
@@ -21,41 +21,36 @@
 
 package main
 
-import (
-	"net"
-)
-
 func init() {
-	cmdDelete.Flag.StringVar(&username, "u", "", "Set the username")
-	cmdDelete.Flag.StringVar(&passwordFilename, "P", "",
-		"Set the name of the password file")
+	cmdDelete.Flag.StringVar(&acctName, "a", "", "Select the account")
 }
 
 var cmdDelete = &command{
-	UsageLine: "delete [options] host[:port] name",
+	UsageLine: "delete [options] name",
 	Run:       runDelete,
 }
 
 func runDelete(cmd *command, args []string) error {
-	if len(args) != 2 {
+	if len(args) != 1 {
 		return usageError("invalid number of arguments")
 	}
 
-	host, port, err := parseHostPort(args[0])
+	scriptName := args[0]
+
+	acct, err := getAccount(&conf, acctName)
 	if err != nil {
 		return err
 	}
 
-	scriptName := args[1]
-
-	username, password, err := usernamePassword(host, port, username,
-		passwordFilename)
-	if err != nil {
+	if err := lookupHostPort(acct); err != nil {
 		return err
 	}
 
-	c, err := dialPlainAuth(net.JoinHostPort(host, port), username,
-		password)
+	if err := readPassword(acct); err != nil {
+		return err
+	}
+
+	c, err := dialPlainAuth(acct)
 	if err != nil {
 		return err
 	}