 (eval-when-compile
   (require 'cl))
 (require 'dash)
+(require 'diff)
 (require 'dired)
 (require 'json-mode)
 (require 'magit-popup)

  "JSON via govc datastore.ls -json on current selection."
  (interactive)
  (let ((govc-args '("-l" "-p")))
    (govc-json-info "datastore.ls" (govc-selection))))

(defun govc-datastore-mkdir (name)
  "Mkdir via govc datastore.mkdir with given NAME."

          tabulated-list-entries entries)
    (tabulated-list-print)))

(defun govc-json-info-selection (command)
  "Run govc COMMAND -json on `govc-selection'."
  (if current-prefix-arg
      (--each (govc-selection) (govc-json-info command it))
    (govc-json-info command (govc-selection))))

(defun govc-json-diff ()
  "Diff two *govc-json* buffers in view."
  (let ((buffers))
    (-each (window-list-1)
      (lambda (w)
        (with-current-buffer (window-buffer w)
          (if (and (eq major-mode 'json-mode)
                   (s-starts-with? "*govc-json*" (buffer-name)))
              (push (current-buffer) buffers)))) )
    (if (= (length buffers) 2)
        (pop-to-buffer
         (diff-no-select (car buffers) (cadr buffers))))))

(defun govc-json-info (command selection)
  "Run govc COMMAND -json on SELECTION."
  (govc-process (govc-command command "-json" govc-args selection)
                (lambda ()
                  (let ((buffer (get-buffer-create (concat "*govc-json*" (if current-prefix-arg selection)))))
                    (copy-to-buffer buffer (point-min) (point-max))
                    (with-current-buffer buffer
                      (json-mode)
                      ;; 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)))

(defun govc-mode-new-session ()
  "Connect new session for the current govc mode."
