Skip to content

Commit

Permalink
Format ls output into columns.
Browse files Browse the repository at this point in the history
Fixes #17. Original code by @grantseltzer
  • Loading branch information
grantseltzer authored and Diwaker Gupta committed Jul 17, 2016
1 parent c9a61ef commit b23826e
Show file tree
Hide file tree
Showing 14 changed files with 1,471 additions and 8 deletions.
36 changes: 28 additions & 8 deletions cmd/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import (
"fmt"
"io"
"os"
"sort"
"strings"
"text/tabwriter"

"github.com/dropbox/dropbox-sdk-go-unofficial/files"
"github.com/dustin/go-humanize"
"github.com/grantseltzer/golumns"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -93,24 +95,42 @@ func ls(cmd *cobra.Command, args []string) (err error) {
}
}

w := new(tabwriter.Writer)
w.Init(os.Stdout, 4, 8, 1, ' ', 0)
long, _ := cmd.Flags().GetBool("long")
if long {
w := new(tabwriter.Writer)
w.Init(os.Stdout, 4, 8, 1, ' ', 0)
fmt.Fprintf(w, "Revision\tSize\tLast modified\tPath\n")
for _, entry := range entries {
switch entry.Tag {
case "folder":
printFolderMetadata(w, entry.Folder, long)
case "file":
printFileMetadata(w, entry.File, long)
}
}
w.Flush()
} else {
entryNames := listOfEntryNames(entries)
golumns.Display(entryNames)
}

for _, e := range entries {
switch e.Tag {
return err
}

func listOfEntryNames(entries []*files.Metadata) []string {
listOfEntryNames := []string{}

for _, entry := range entries {
switch entry.Tag {
case "folder":
printFolderMetadata(w, e.Folder, long)
listOfEntryNames = append(listOfEntryNames, entry.Folder.Name)
case "file":
printFileMetadata(w, e.File, long)
listOfEntryNames = append(listOfEntryNames, entry.File.Name)
}
}
w.Flush()

return err
sort.Strings(listOfEntryNames)
return listOfEntryNames
}

// lsCmd represents the ls command
Expand Down
Empty file.
13 changes: 13 additions & 0 deletions vendor/github.com/GrantSeltzer/golumns/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions vendor/github.com/GrantSeltzer/golumns/columns.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions vendor/github.com/GrantSeltzer/golumns/display.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/golang.org/x/crypto/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/golang.org/x/crypto/PATENTS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b23826e

Please sign in to comment.