Skip to content

Commit c60f498

Browse files
committed
govc: add datastore.ls -H option
Use human friendly name by default, rather than vSAN ID for top-level dirs. Note that the datastore.ls command was originally written against vSphere 5.5, the 'FileInfo.FriendlyName' field was not added until 6.5 Signed-off-by: Doug MacEachern <[email protected]>
1 parent 3def2df commit c60f498

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

cli/datastore/ls.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type ls struct {
4242
slash bool
4343
all bool
4444
recurse bool
45+
human bool
4546
}
4647

4748
func init() {
@@ -55,6 +56,7 @@ func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
5556
cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
5657
cmd.OutputFlag.Register(ctx, f)
5758

59+
f.BoolVar(&cmd.human, "H", true, "Display human friendly name") // vSAN top-level dirs are ID by default
5860
f.BoolVar(&cmd.long, "l", false, "Long listing format")
5961
f.BoolVar(&cmd.slash, "p", false, "Append / indicator to directories")
6062
f.BoolVar(&cmd.all, "a", false, "Do not ignore entries starting with .")
@@ -206,10 +208,17 @@ func (o *listOutput) add(r types.HostDatastoreBrowserSearchResults) {
206208
res.File = nil
207209

208210
for _, f := range r.File {
209-
if f.GetFileInfo().Path[0] == '.' && !o.cmd.all {
211+
info := f.GetFileInfo()
212+
if info.Path[0] == '.' && !o.cmd.all {
210213
continue
211214
}
212215

216+
if o.cmd.human {
217+
if info.FriendlyName != "" {
218+
info.Path = info.FriendlyName
219+
}
220+
}
221+
213222
if o.cmd.slash {
214223
if d, ok := f.(*types.FolderFileInfo); ok {
215224
d.Path += "/"

govc/USAGE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ Options:
14581458
Usage: govc datastore.ls [OPTIONS] [FILE]...
14591459
14601460
Options:
1461+
-H=true Display human friendly name
14611462
-R=false List subdirectories recursively
14621463
-a=false Do not ignore entries starting with .
14631464
-ds= Datastore [GOVC_DATASTORE]

0 commit comments

Comments
 (0)