projects/sievemgr

changeset 7:3abc8be485c0

Add rename subcommand for renaming scripts on the server
author Guido Berhoerster <guido+sievemgr@berhoerster.name>
date Sat Nov 07 16:48:55 2020 +0100 (3 months ago)
parents 2130614cd64a
children 8caacf702c0d
files cmd/sievemgr/main.go cmd/sievemgr/rename.go
line diff
     1.1 --- a/cmd/sievemgr/main.go	Sat Nov 07 09:28:27 2020 +0100
     1.2 +++ b/cmd/sievemgr/main.go	Sat Nov 07 16:48:55 2020 +0100
     1.3 @@ -69,6 +69,7 @@
     1.4  	cmdInfo,
     1.5  	cmdCheck,
     1.6  	cmdCheckSpace,
     1.7 +	cmdRename,
     1.8  }
     1.9  
    1.10  func usage() {
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/cmd/sievemgr/rename.go	Sat Nov 07 16:48:55 2020 +0100
     2.3 @@ -0,0 +1,65 @@
     2.4 +// Copyright (C) 2020 Guido Berhoerster <guido+sievemgr@berhoerster.name>
     2.5 +//
     2.6 +// Permission is hereby granted, free of charge, to any person obtaining
     2.7 +// a copy of this software and associated documentation files (the
     2.8 +// "Software"), to deal in the Software without restriction, including
     2.9 +// without limitation the rights to use, copy, modify, merge, publish,
    2.10 +// distribute, sublicense, and/or sell copies of the Software, and to
    2.11 +// permit persons to whom the Software is furnished to do so, subject to
    2.12 +// the following conditions:
    2.13 +//
    2.14 +// The above copyright notice and this permission notice shall be included
    2.15 +// in all copies or substantial portions of the Software.
    2.16 +//
    2.17 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    2.18 +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    2.19 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    2.20 +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    2.21 +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    2.22 +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    2.23 +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    2.24 +
    2.25 +package main
    2.26 +
    2.27 +func init() {
    2.28 +	cmdRename.Flag.StringVar(&acctName, "a", "", "Select the account")
    2.29 +}
    2.30 +
    2.31 +var cmdRename = &command{
    2.32 +	UsageLine: "rename [options] old new",
    2.33 +	Run:       runRename,
    2.34 +}
    2.35 +
    2.36 +func runRename(cmd *command, args []string) error {
    2.37 +	if len(args) != 2 {
    2.38 +		return usageError("invalid number of arguments")
    2.39 +	}
    2.40 +
    2.41 +	oldName, newName := args[0], args[1]
    2.42 +
    2.43 +	acct, err := getAccount(&conf, acctName)
    2.44 +	if err != nil {
    2.45 +		return err
    2.46 +	}
    2.47 +
    2.48 +	if err := lookupHostPort(acct); err != nil {
    2.49 +		return err
    2.50 +	}
    2.51 +
    2.52 +	if err := readPassword(acct); err != nil {
    2.53 +		return err
    2.54 +	}
    2.55 +
    2.56 +	c, err := dialPlainAuth(acct)
    2.57 +	if err != nil {
    2.58 +		return err
    2.59 +	}
    2.60 +	defer c.Logout()
    2.61 +
    2.62 +	err = c.RenameScript(oldName, newName)
    2.63 +	if err != nil {
    2.64 +		return err
    2.65 +	}
    2.66 +
    2.67 +	return nil
    2.68 +}