github.com/vmware/govmomi@v0.43.0/govc/vm/guest/rm.go (about)

     1  /*
     2  Copyright (c) 2014-2017 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 guest
    18  
    19  import (
    20  	"context"
    21  	"flag"
    22  
    23  	"github.com/vmware/govmomi/govc/cli"
    24  )
    25  
    26  type rm struct {
    27  	*GuestFlag
    28  }
    29  
    30  func init() {
    31  	cli.Register("guest.rm", &rm{})
    32  }
    33  
    34  func (cmd *rm) Register(ctx context.Context, f *flag.FlagSet) {
    35  	cmd.GuestFlag, ctx = newGuestFlag(ctx)
    36  	cmd.GuestFlag.Register(ctx, f)
    37  }
    38  
    39  func (cmd *rm) Process(ctx context.Context) error {
    40  	if err := cmd.GuestFlag.Process(ctx); err != nil {
    41  		return err
    42  	}
    43  	return nil
    44  }
    45  
    46  func (cmd *rm) Usage() string {
    47  	return "PATH"
    48  }
    49  
    50  func (cmd *rm) Description() string {
    51  	return `Remove file PATH in VM.
    52  
    53  Examples:
    54    govc guest.rm -vm $name /tmp/foo.log`
    55  }
    56  
    57  func (cmd *rm) Run(ctx context.Context, f *flag.FlagSet) error {
    58  	m, err := cmd.FileManager()
    59  	if err != nil {
    60  		return err
    61  	}
    62  
    63  	return m.DeleteFile(ctx, cmd.Auth(), f.Arg(0))
    64  }