Skip to content

Commit

Permalink
govc: add datastore.ls -H option
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dougm committed Dec 19, 2024
1 parent 3def2df commit c60f498
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cli/datastore/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ls struct {
slash bool
all bool
recurse bool
human bool
}

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

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

for _, f := range r.File {
if f.GetFileInfo().Path[0] == '.' && !o.cmd.all {
info := f.GetFileInfo()
if info.Path[0] == '.' && !o.cmd.all {
continue
}

if o.cmd.human {
if info.FriendlyName != "" {
info.Path = info.FriendlyName
}
}

if o.cmd.slash {
if d, ok := f.(*types.FolderFileInfo); ok {
d.Path += "/"
Expand Down
1 change: 1 addition & 0 deletions govc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@ Options:
Usage: govc datastore.ls [OPTIONS] [FILE]...
Options:
-H=true Display human friendly name
-R=false List subdirectories recursively
-a=false Do not ignore entries starting with .
-ds= Datastore [GOVC_DATASTORE]
Expand Down

0 comments on commit c60f498

Please sign in to comment.