# HG changeset patch # User Guido Berhoerster # Date 1604764135 -3600 # Node ID 3abc8be485c06ebee7ba9e885adda2c3f185da43 # Parent 2130614cd64a31299cb8432c235ace51f5fdaacf Add rename subcommand for renaming scripts on the server diff -r 2130614cd64a -r 3abc8be485c0 cmd/sievemgr/main.go --- a/cmd/sievemgr/main.go Sat Nov 07 09:28:27 2020 +0100 +++ b/cmd/sievemgr/main.go Sat Nov 07 16:48:55 2020 +0100 @@ -69,6 +69,7 @@ cmdInfo, cmdCheck, cmdCheckSpace, + cmdRename, } func usage() { diff -r 2130614cd64a -r 3abc8be485c0 cmd/sievemgr/rename.go --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmd/sievemgr/rename.go Sat Nov 07 16:48:55 2020 +0100 @@ -0,0 +1,65 @@ +// Copyright (C) 2020 Guido Berhoerster +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +package main + +func init() { + cmdRename.Flag.StringVar(&acctName, "a", "", "Select the account") +} + +var cmdRename = &command{ + UsageLine: "rename [options] old new", + Run: runRename, +} + +func runRename(cmd *command, args []string) error { + if len(args) != 2 { + return usageError("invalid number of arguments") + } + + oldName, newName := args[0], args[1] + + acct, err := getAccount(&conf, acctName) + if err != nil { + return err + } + + if err := lookupHostPort(acct); err != nil { + return err + } + + if err := readPassword(acct); err != nil { + return err + } + + c, err := dialPlainAuth(acct) + if err != nil { + return err + } + defer c.Logout() + + err = c.RenameScript(oldName, newName) + if err != nil { + return err + } + + return nil +}