2
Copyright (c) 2014 VMware, Inc. All Rights Reserved.
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
8
http://www.apache.org/licenses/LICENSE-2.0
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.
27
"github.com/juju/govmomi/govc/cli"
28
"github.com/juju/govmomi/govc/flags"
36
cli.Register("host.esxcli", &esxcli{})
39
func (cmd *esxcli) Register(f *flag.FlagSet) {}
41
func (cmd *esxcli) Process() error { return nil }
43
func (cmd *esxcli) Run(f *flag.FlagSet) error {
44
c, err := cmd.Client()
49
host, err := cmd.HostSystem()
54
e, err := NewExecutor(c, host)
59
res, err := e.Run(f.Args())
64
if len(res.Values) == 0 {
68
// TODO: OutputFlag / format options
69
switch res.Info.Hints.Formatter() {
79
func (cmd *esxcli) formatSimple(res *Response) {
81
for key := range res.Values[0] {
82
keys = append(keys, key)
86
tw := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
88
for i, rv := range res.Values {
93
for _, key := range keys {
94
fmt.Fprintf(tw, "%s:\t%s\n", key, strings.Join(rv[key], ", "))
101
func (cmd *esxcli) formatTable(res *Response) {
102
fields := res.Info.Hints.Fields()
104
tw := tabwriter.NewWriter(os.Stdout, len(fields), 0, 2, ' ', 0)
107
for _, name := range fields {
108
hr = append(hr, strings.Repeat("-", len(name)))
111
fmt.Fprintln(tw, strings.Join(fields, "\t"))
112
fmt.Fprintln(tw, strings.Join(hr, "\t"))
114
for _, vals := range res.Values {
117
for _, name := range fields {
118
key := strings.Replace(name, " ", "", -1)
119
if val, ok := vals[key]; ok {
120
row = append(row, strings.Join(val, ", "))
122
row = append(row, "")
126
fmt.Fprintln(tw, strings.Join(row, "\t"))