Skip to content

Commit

Permalink
Add govc-command customization option
Browse files Browse the repository at this point in the history
  • Loading branch information
tzz committed Dec 13, 2016
1 parent ad6e563 commit de12e4a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions govc/emacs/govc.el
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"Prefix for `govc-mode'."
:group 'govc)

(defcustom govc-command "govc"
"Executable path to the govc utility."
:type 'string
:group 'govc)

(defvar govc-command-map
(let ((map (make-sparse-keymap)))
(define-key map "h" 'govc-host)
Expand Down Expand Up @@ -299,9 +304,9 @@ Return value is the url anchor if set, otherwise the hostname is returned."
(if url
(or (url-target url) (url-host url)))))

(defun govc-command (command &rest args)
(defun govc-format-command (command &rest args)
"Format govc COMMAND ARGS."
(format "govc %s %s" command
(format "%s %s %s" govc-command command
(s-join " " (--map (format "'%s'" it)
(-flatten (-non-nil args))))))

Expand Down Expand Up @@ -350,14 +355,14 @@ Optionally set `GOVC_*' vars in `process-environment' using prefix
(defun govc (command &rest args)
"Execute govc COMMAND with ARGS.
Return value is `buffer-string' split on newlines."
(govc-process (govc-command command args)
(govc-process (govc-format-command command args)
(lambda ()
(split-string (buffer-string) "\n" t))))

(defun govc-json (command &rest args)
"Execute govc COMMAND passing arguments ARGS.
Return value is `json-read'."
(govc-process (govc-command command (cons "-json" args))
(govc-process (govc-format-command command (cons "-json" args))
(lambda ()
(goto-char (point-min))
(let ((json-object-type 'plist))
Expand Down Expand Up @@ -475,8 +480,8 @@ Also fixes the case where user contains an '@'."
"Events via govc events -n `govc-max-events'."
(interactive)
(govc-shell-command
(govc-command "events"
(list "-n" govc-max-events (if current-prefix-arg "-f") (govc-selection)))))
(govc-format-command "events"
(list "-n" govc-max-events (if current-prefix-arg "-f") (govc-selection)))))

(defun govc-parse-info (output)
"Parse govc info command OUTPUT."
Expand Down Expand Up @@ -567,7 +572,7 @@ Also fixes the case where user contains an '@'."

(defun govc-json-info (command selection)
"Run govc COMMAND -json on SELECTION."
(govc-process (govc-command command "-json" govc-args selection)
(govc-process (govc-format-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))
Expand Down Expand Up @@ -846,8 +851,8 @@ Optionally filter by FILTER and inherit SESSION."
"Tail datastore file."
(interactive)
(govc-shell-command
(govc-command "datastore.tail"
(list "-n" govc-max-events (if current-prefix-arg "-f")) (govc-selection))))
(govc-format-command "datastore.tail"
(list "-n" govc-max-events (if current-prefix-arg "-f")) (govc-selection))))

(defun govc-datastore-ls-json ()
"JSON via govc datastore.ls -json on current selection."
Expand Down

0 comments on commit de12e4a

Please sign in to comment.