github.com/vmware/govmomi@v0.37.1/govc/datastore/mv.go (about) 1 /* 2 Copyright (c) 2014-2018 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package datastore 18 19 import ( 20 "context" 21 "flag" 22 "fmt" 23 24 "github.com/vmware/govmomi/govc/cli" 25 ) 26 27 type mv struct { 28 target 29 } 30 31 func init() { 32 cli.Register("datastore.mv", &mv{}) 33 } 34 35 func (cmd *mv) Usage() string { 36 return "SRC DST" 37 } 38 39 func (cmd *mv) Description() string { 40 return `Move SRC to DST on DATASTORE. 41 42 Examples: 43 govc datastore.mv foo/foo.vmx foo/foo.vmx.old 44 govc datastore.mv -f my.vmx foo/foo.vmx` 45 } 46 47 func (cmd *mv) Run(ctx context.Context, f *flag.FlagSet) error { 48 args := f.Args() 49 if len(args) != 2 { 50 return flag.ErrHelp 51 } 52 53 m, err := cmd.FileManager() 54 if err != nil { 55 return err 56 } 57 58 src, err := cmd.DatastorePath(args[0]) 59 if err != nil { 60 return err 61 } 62 63 dst, err := cmd.target.ds.DatastorePath(args[1]) 64 if err != nil { 65 return err 66 } 67 68 mv := m.MoveFile 69 if cmd.kind { 70 mv = m.Move 71 } 72 73 logger := cmd.ProgressLogger(fmt.Sprintf("Moving %s to %s...", src, dst)) 74 defer logger.Wait() 75 76 return mv(m.WithProgress(ctx, logger), src, dst) 77 }