Mercurial > projects > sievemgr
changeset 7:3abc8be485c0
Add rename subcommand for renaming scripts on the server
author | Guido Berhoerster <guido+sievemgr@berhoerster.name> |
---|---|
date | Sat, 07 Nov 2020 16:48:55 +0100 |
parents | 2130614cd64a |
children | 8caacf702c0d |
files | cmd/sievemgr/main.go cmd/sievemgr/rename.go |
diffstat | 2 files changed, 66 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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() {
--- /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 <guido+sievemgr@berhoerster.name> +// +// 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 +}