projects/sievemgr
annotate cmd/sievemgr/delete.go @ 1:0cd5a454dfb4
Add README file
Adjust email address.
Adjust email address.
author | Guido Berhoerster <guido+sievemgr@berhoerster.name> |
---|---|
date | Mon Oct 26 14:46:39 2020 +0100 (19 months ago) |
parents | b00673734e58 |
children | 4dff4c3f0fbb |
rev | line source |
---|---|
guido+sievemgr@1 | 1 // Copyright (C) 2020 Guido Berhoerster <guido+sievemgr@berhoerster.name> |
guido+sievemgr@0 | 2 // |
guido+sievemgr@0 | 3 // Permission is hereby granted, free of charge, to any person obtaining |
guido+sievemgr@0 | 4 // a copy of this software and associated documentation files (the |
guido+sievemgr@0 | 5 // "Software"), to deal in the Software without restriction, including |
guido+sievemgr@0 | 6 // without limitation the rights to use, copy, modify, merge, publish, |
guido+sievemgr@0 | 7 // distribute, sublicense, and/or sell copies of the Software, and to |
guido+sievemgr@0 | 8 // permit persons to whom the Software is furnished to do so, subject to |
guido+sievemgr@0 | 9 // the following conditions: |
guido+sievemgr@0 | 10 // |
guido+sievemgr@0 | 11 // The above copyright notice and this permission notice shall be included |
guido+sievemgr@0 | 12 // in all copies or substantial portions of the Software. |
guido+sievemgr@0 | 13 // |
guido+sievemgr@0 | 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
guido+sievemgr@0 | 15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
guido+sievemgr@0 | 16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
guido+sievemgr@0 | 17 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
guido+sievemgr@0 | 18 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
guido+sievemgr@0 | 19 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
guido+sievemgr@0 | 20 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
guido+sievemgr@0 | 21 |
guido+sievemgr@0 | 22 package main |
guido+sievemgr@0 | 23 |
guido+sievemgr@0 | 24 import ( |
guido+sievemgr@0 | 25 "net" |
guido+sievemgr@0 | 26 ) |
guido+sievemgr@0 | 27 |
guido+sievemgr@0 | 28 func init() { |
guido+sievemgr@0 | 29 cmdDelete.Flag.StringVar(&username, "u", "", "Set the username") |
guido+sievemgr@0 | 30 cmdDelete.Flag.StringVar(&passwordFilename, "P", "", |
guido+sievemgr@0 | 31 "Set the name of the password file") |
guido+sievemgr@0 | 32 } |
guido+sievemgr@0 | 33 |
guido+sievemgr@0 | 34 var cmdDelete = &command{ |
guido+sievemgr@0 | 35 UsageLine: "delete [options] host[:port] name", |
guido+sievemgr@0 | 36 Run: runDelete, |
guido+sievemgr@0 | 37 } |
guido+sievemgr@0 | 38 |
guido+sievemgr@0 | 39 func runDelete(cmd *command, args []string) error { |
guido+sievemgr@0 | 40 if len(args) != 2 { |
guido+sievemgr@0 | 41 return usageError("invalid number of arguments") |
guido+sievemgr@0 | 42 } |
guido+sievemgr@0 | 43 |
guido+sievemgr@0 | 44 host, port, err := parseHostPort(args[0]) |
guido+sievemgr@0 | 45 if err != nil { |
guido+sievemgr@0 | 46 return err |
guido+sievemgr@0 | 47 } |
guido+sievemgr@0 | 48 |
guido+sievemgr@0 | 49 scriptName := args[1] |
guido+sievemgr@0 | 50 |
guido+sievemgr@0 | 51 username, password, err := usernamePassword(host, port, username, |
guido+sievemgr@0 | 52 passwordFilename) |
guido+sievemgr@0 | 53 if err != nil { |
guido+sievemgr@0 | 54 return err |
guido+sievemgr@0 | 55 } |
guido+sievemgr@0 | 56 |
guido+sievemgr@0 | 57 c, err := dialPlainAuth(net.JoinHostPort(host, port), username, |
guido+sievemgr@0 | 58 password) |
guido+sievemgr@0 | 59 if err != nil { |
guido+sievemgr@0 | 60 return err |
guido+sievemgr@0 | 61 } |
guido+sievemgr@0 | 62 defer c.Logout() |
guido+sievemgr@0 | 63 |
guido+sievemgr@0 | 64 if err := c.DeleteScript(scriptName); err != nil { |
guido+sievemgr@0 | 65 return err |
guido+sievemgr@0 | 66 } |
guido+sievemgr@0 | 67 |
guido+sievemgr@0 | 68 return nil |
guido+sievemgr@0 | 69 } |