diff --git a/cmd/ls.go b/cmd/ls.go index 1b6be59..9ae3d0f 100644 --- a/cmd/ls.go +++ b/cmd/ls.go @@ -44,9 +44,13 @@ func printFolderMetadata(w io.Writer, e *files.FolderMetadata, longFormat bool) fmt.Fprintf(w, "%s\t", e.PathDisplay) } -func printFileMetadata(w io.Writer, e *files.FileMetadata, longFormat bool) { +func printFileMetadata(w io.Writer, e *files.FileMetadata, longFormat bool, machineReadable bool) { if longFormat { - fmt.Fprintf(w, "%s\t%s\t%s\t", e.Rev, humanize.IBytes(e.Size), humanize.Time(e.ServerModified)) + if (machineReadable) { + fmt.Fprintf(w, "%s\t%d\t%s\t", e.Rev, e.Size, e.ServerModified) + } else { + fmt.Fprintf(w, "%s\t%s\t%s\t", e.Rev, humanize.IBytes(e.Size), humanize.Time(e.ServerModified)) + } } fmt.Fprintf(w, "%s\t", e.PathDisplay) } @@ -101,7 +105,12 @@ func ls(cmd *cobra.Command, args []string) (err error) { } } + machineReadable, _ := cmd.Flags().GetBool("machine") long, _ := cmd.Flags().GetBool("long") + + //If machine is set imply long + long = long || machineReadable + w := new(tabwriter.Writer) w.Init(os.Stdout, 4, 8, 1, ' ', 0) if long { @@ -110,7 +119,7 @@ func ls(cmd *cobra.Command, args []string) (err error) { for i, entry := range entries { switch f := entry.(type) { case *files.FileMetadata: - printFileMetadata(w, f, long) + printFileMetadata(w, f, long, machineReadable) case *files.FolderMetadata: printFolderMetadata(w, f, long) } @@ -139,4 +148,5 @@ func init() { lsCmd.Flags().BoolP("long", "l", false, "Long listing") lsCmd.Flags().BoolP("recurse", "R", false, "Recursively list all subfolders") + lsCmd.Flags().BoolP("machine", "m", false, "Machine readable file size and time") } diff --git a/cmd/revs.go b/cmd/revs.go index 14f425b..25de4c5 100644 --- a/cmd/revs.go +++ b/cmd/revs.go @@ -41,15 +41,19 @@ func revs(cmd *cobra.Command, args []string) (err error) { return } + machineReadable, _ := cmd.Flags().GetBool("machine") long, _ := cmd.Flags().GetBool("long") + //If machine is set imply long + long = long || machineReadable + if long { fmt.Printf("Revision\tSize\tLast modified\tPath\n") } for _, e := range res.Entries { if long { - printFileMetadata(os.Stdout, e, long) + printFileMetadata(os.Stdout, e, long, machineReadable) } else { fmt.Printf("%s\n", e.Rev) } @@ -69,4 +73,5 @@ func init() { RootCmd.AddCommand(revsCmd) revsCmd.Flags().BoolP("long", "l", false, "Long listing") + revsCmd.Flags().BoolP("machine", "m", false, "Machine readable file size and time") } diff --git a/cmd/search.go b/cmd/search.go index 1790d5d..80398ac 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -46,7 +46,12 @@ func search(cmd *cobra.Command, args []string) (err error) { return } + machineReadable, _ := cmd.Flags().GetBool("machine") long, _ := cmd.Flags().GetBool("long") + + //If machine is set imply long + long = long || machineReadable + if long { fmt.Printf("Revision\tSize\tLast modified\tPath\n") } @@ -54,7 +59,7 @@ func search(cmd *cobra.Command, args []string) (err error) { for _, m := range res.Matches { switch f := m.Metadata.(type) { case *files.FileMetadata: - printFileMetadata(os.Stdout, f, long) + printFileMetadata(os.Stdout, f, long, machineReadable) case *files.FolderMetadata: printFolderMetadata(os.Stdout, f, long) } @@ -73,4 +78,5 @@ var searchCmd = &cobra.Command{ func init() { RootCmd.AddCommand(searchCmd) searchCmd.Flags().BoolP("long", "l", false, "Long listing") + searchCmd.Flags().BoolP("machine", "m", false, "Machine readable file size and time") } diff --git a/contrib/zsh-completion/_dbxcli b/contrib/zsh-completion/_dbxcli index 8717a8d..45012b4 100644 --- a/contrib/zsh-completion/_dbxcli +++ b/contrib/zsh-completion/_dbxcli @@ -24,6 +24,7 @@ function _dbxcli() { _arguments -C \ '(-l --long)'{-l,--long}'[Long listing]' \ '(-h --help)'{-h,--help}'[Print information about a command]' \ + '(-m --machine)'{-m,--machine}'[Output machine readable file sizes and times]' \ '--token[(string) Access token]' \ '(-v --verbose)'{-v,--verbose}'[Enable verbose logging]' \ && ret=0