Repository: vmware/govmomi
Pull request #2840 (2022-05-11 07:55:35)

Fixed docs for govc library.info w/-json
Fixed docs for govc library.info w/-json

When -json comes after the "library/item" then it does not trigger JSON output.


Patch:
diff --git a/govc/USAGE.md b/govc/USAGE.md
index 02a55541..3f8fd375 100644
--- a/govc/USAGE.md
+++ b/govc/USAGE.md
@@ -86,7 +86,6 @@ but appear via `govc $cmd -h`:
  - [device.cdrom.add](#devicecdromadd)
  - [device.cdrom.eject](#devicecdromeject)
  - [device.cdrom.insert](#devicecdrominsert)
- - [device.clock.add](#deviceclockadd)
  - [device.connect](#deviceconnect)
  - [device.disconnect](#devicedisconnect)
  - [device.floppy.add](#devicefloppyadd)
@@ -1276,21 +1275,6 @@ Options:
   -vm=                   Virtual machine [GOVC_VM]
 ```
 
-## device.clock.add
-
-```
-Usage: govc device.clock.add [OPTIONS]
-
-Add precision clock device to VM.
-
-Examples:
-  govc device.clock.add -vm $vm
-  govc device.info clock-*
-
-Options:
-  -vm=                   Virtual machine [GOVC_VM]
-```
-
 ## device.connect
 
 ```
@@ -3301,7 +3285,7 @@ Examples:
   govc library.info */
   govc device.cdrom.insert -vm $vm -device cdrom-3000 $(govc library.info -L /lib1/item1/file1)
   govc library.info -json | jq .
-  govc library.info /lib1/item1 -json | jq .
+  govc library.info -json /lib1/item1 | jq .
 
 Options:
   -L=false               List Datastore path only
diff --git a/govc/device/clock/add.go b/govc/device/clock/add.go
deleted file mode 100644
index c984d5f3..00000000
--- a/govc/device/clock/add.go
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
-Copyright (c) 2022 VMware, Inc. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package floppy
-
-import (
-	"context"
-	"flag"
-	"fmt"
-
-	"github.com/vmware/govmomi/govc/cli"
-	"github.com/vmware/govmomi/govc/flags"
-	"github.com/vmware/govmomi/vim25/types"
-)
-
-type add struct {
-	*flags.VirtualMachineFlag
-}
-
-func init() {
-	cli.Register("device.clock.add", &add{})
-}
-
-func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
-	cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
-	cmd.VirtualMachineFlag.Register(ctx, f)
-}
-
-func (cmd *add) Description() string {
-	return `Add precision clock device to VM.
-
-Examples:
-  govc device.clock.add -vm $vm
-  govc device.info clock-*`
-}
-
-func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
-	vm, err := cmd.VirtualMachine()
-	if err != nil {
-		return err
-	}
-
-	if vm == nil {
-		return flag.ErrHelp
-	}
-
-	d := &types.VirtualPrecisionClock{
-		VirtualDevice: types.VirtualDevice{
-			Backing: &types.VirtualPrecisionClockSystemClockBackingInfo{
-				Protocol: string(types.HostDateTimeInfoProtocolPtp), // TODO: ntp option
-			},
-		},
-	}
-
-	err = vm.AddDevice(ctx, d)
-	if err != nil {
-		return err
-	}
-
-	// output name of device we just created
-	devices, err := vm.Device(ctx)
-	if err != nil {
-		return err
-	}
-
-	devices = devices.SelectByType(d)
-
-	name := devices.Name(devices[len(devices)-1])
-
-	fmt.Println(name)
-
-	return nil
-}
diff --git a/govc/device/info.go b/govc/device/info.go
index 4c7d4a08..bf561bc8 100644
--- a/govc/device/info.go
+++ b/govc/device/info.go
@@ -243,14 +243,6 @@ func (r *infoResult) Write(w io.Writer) error {
 				fmt.Fprintf(tw, "  Service URI:\t%s\n", b.ServiceURI)
 				fmt.Fprintf(tw, "  Proxy URI:\t%s\n", b.ProxyURI)
 			}
-		case *types.VirtualPrecisionClock:
-			if b, ok := md.Backing.(*types.VirtualPrecisionClockSystemClockBackingInfo); ok {
-				proto := b.Protocol
-				if proto == "" {
-					proto = string(types.HostDateTimeInfoProtocolPtp)
-				}
-				fmt.Fprintf(tw, "  Protocol:\t%s\n", proto)
-			}
 		}
 	}
 
diff --git a/govc/emacs/govc.el b/govc/emacs/govc.el
index c7f08449..d30f5849 100644
--- a/govc/emacs/govc.el
+++ b/govc/emacs/govc.el
@@ -743,7 +743,8 @@ returned, assuming that's what the user wanted."
                     (copy-to-buffer buffer (point-min) (point-max))
                     (with-current-buffer buffer
                       (json-mode)
-                      (json-pretty-print-buffer))
+                      ;; We use `json-mode-beautify' as `json-pretty-print-buffer' does not work for `govc-host-json-info'
+                      (json-mode-beautify))
                     (display-buffer buffer))))
   (if current-prefix-arg
       (govc-json-diff)))
diff --git a/govc/library/info.go b/govc/library/info.go
index 72bd9a4f..b10ebc08 100644
--- a/govc/library/info.go
+++ b/govc/library/info.go
@@ -89,7 +89,7 @@ Examples:
   govc library.info */
   govc device.cdrom.insert -vm $vm -device cdrom-3000 $(govc library.info -L /lib1/item1/file1)
   govc library.info -json | jq .
-  govc library.info /lib1/item1 -json | jq .`
+  govc library.info -json /lib1/item1 | jq .`
 }
 
 type infoResultsWriter struct {
diff --git a/govc/main.go b/govc/main.go
index 2493c24c..ec91ae7d 100644
--- a/govc/main.go
+++ b/govc/main.go
@@ -34,7 +34,6 @@ import (
 	_ "github.com/vmware/govmomi/govc/datastore/vsan"
 	_ "github.com/vmware/govmomi/govc/device"
 	_ "github.com/vmware/govmomi/govc/device/cdrom"
-	_ "github.com/vmware/govmomi/govc/device/clock"
 	_ "github.com/vmware/govmomi/govc/device/floppy"
 	_ "github.com/vmware/govmomi/govc/device/pci"
 	_ "github.com/vmware/govmomi/govc/device/scsi"
diff --git a/object/virtual_device_list.go b/object/virtual_device_list.go
index edf071c5..30bd1705 100644
--- a/object/virtual_device_list.go
+++ b/object/virtual_device_list.go
@@ -894,8 +894,6 @@ func (l VirtualDeviceList) Type(device types.BaseVirtualDevice) string {
 		return "lsilogic-sas"
 	case *types.VirtualNVMEController:
 		return "nvme"
-	case *types.VirtualPrecisionClock:
-		return "clock"
 	default:
 		return l.deviceName(device)
 	}


Test patch:
diff --git a/govc/test/device.bats b/govc/test/device.bats
index 62928585..b064563c 100755
--- a/govc/test/device.bats
+++ b/govc/test/device.bats
@@ -279,22 +279,6 @@ load test_helper
   [ $result -eq 1 ]
 }
 
-@test "device.clock" {
-  vcsim_env
-
-  vm=$(new_empty_vm)
-
-  result=$(govc device.ls -vm "$vm" | grep clock | wc -l)
-  [ "$result" -eq 0 ]
-
-  run govc device.clock.add -vm "$vm"
-  assert_success
-  id=$output
-
-  result=$(govc device.ls -vm "$vm" | grep "$id" | wc -l)
-  [ "$result" -eq 1 ]
-}
-
 @test "device.scsi slots" {
   vcsim_env