Only show transfer stats on commands which transfer stuff - fixes #849

This commit is contained in:
Nick Craig-Wood 2016-12-04 16:52:24 +00:00
parent 716ce49ce9
commit 2cbdb95ce5
22 changed files with 30 additions and 25 deletions

View File

@ -33,7 +33,7 @@ Or like this to output any .txt files in dir or subdirectories.
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fsrc := cmd.NewFsSrc(args)
cmd.Run(false, command, func() error {
cmd.Run(false, false, command, func() error {
return fs.Cat(fsrc, os.Stdout)
})
},

View File

@ -23,7 +23,7 @@ don't match. It doesn't alter the source or destination.
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(2, 2, command, args)
fsrc, fdst := cmd.NewFsSrcDst(args)
cmd.Run(false, command, func() error {
cmd.Run(false, false, command, func() error {
return fs.Check(fdst, fsrc)
})
},

View File

@ -20,7 +20,7 @@ versions. Not supported by all remotes.
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fsrc := cmd.NewFsSrc(args)
cmd.Run(true, command, func() error {
cmd.Run(true, false, command, func() error {
return fs.CleanUp(fsrc)
})
},

View File

@ -225,9 +225,12 @@ func NewFsDst(args []string) fs.Fs {
}
// Run the function with stats and retries if required
func Run(Retry bool, cmd *cobra.Command, f func() error) {
func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
var err error
stopStats := startStats()
var stopStats chan struct{}
if showStats {
stopStats = startStats()
}
for try := 1; try <= *retries; try++ {
err = f()
if !Retry || (err == nil && !fs.Stats.Errored()) {
@ -253,11 +256,13 @@ func Run(Retry bool, cmd *cobra.Command, f func() error) {
fs.Stats.ResetErrors()
}
}
close(stopStats)
if showStats {
close(stopStats)
}
if err != nil {
log.Fatalf("Failed to %s: %v", cmd.Name(), err)
}
if !fs.Config.Quiet || fs.Stats.Errored() || *statsInterval > 0 {
if showStats && (!fs.Config.Quiet || fs.Stats.Errored() || *statsInterval > 0) {
fs.Log(nil, "%s", fs.Stats)
}
if fs.Config.Verbose {

View File

@ -56,7 +56,7 @@ the destination directory or not.
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(2, 2, command, args)
fsrc, fdst := cmd.NewFsSrcDst(args)
cmd.Run(true, command, func() error {
cmd.Run(true, true, command, func() error {
return fs.CopyDir(fdst, fsrc)
})
},

View File

@ -43,7 +43,7 @@ destination.
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(2, 2, command, args)
fsrc, srcFileName, fdst, dstFileName := cmd.NewFsSrcDstFiles(args)
cmd.Run(true, command, func() error {
cmd.Run(true, true, command, func() error {
if srcFileName == "" {
return fs.CopyDir(fdst, fsrc)
}

View File

@ -106,7 +106,7 @@ Or
args = args[1:]
}
fdst := cmd.NewFsSrc(args)
cmd.Run(false, command, func() error {
cmd.Run(false, false, command, func() error {
return fs.Deduplicate(fdst, dedupeMode)
})
},

View File

@ -34,7 +34,7 @@ delete all files bigger than 100MBytes.
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fsrc := cmd.NewFsSrc(args)
cmd.Run(true, command, func() error {
cmd.Run(true, false, command, func() error {
return fs.Delete(fsrc)
})
},

View File

@ -18,7 +18,7 @@ var commandDefintion = &cobra.Command{
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fsrc := cmd.NewFsSrc(args)
cmd.Run(false, command, func() error {
cmd.Run(false, false, command, func() error {
return fs.List(fsrc, os.Stdout)
})
},

View File

@ -18,7 +18,7 @@ var commandDefintion = &cobra.Command{
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fsrc := cmd.NewFsSrc(args)
cmd.Run(false, command, func() error {
cmd.Run(false, false, command, func() error {
return fs.ListDir(fsrc, os.Stdout)
})
},

View File

@ -18,7 +18,7 @@ var commandDefintion = &cobra.Command{
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fsrc := cmd.NewFsSrc(args)
cmd.Run(false, command, func() error {
cmd.Run(false, false, command, func() error {
return fs.ListLong(fsrc, os.Stdout)
})
},

View File

@ -22,7 +22,7 @@ is in the same format as the standard md5sum tool produces.
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fsrc := cmd.NewFsSrc(args)
cmd.Run(false, command, func() error {
cmd.Run(false, false, command, func() error {
return fs.Md5sum(fsrc, os.Stdout)
})
},

View File

@ -20,7 +20,7 @@ var commandDefintion = &cobra.Command{
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fsrc := cmd.NewFsSrc(args)
cmd.Run(false, command, func() error {
cmd.Run(false, false, command, func() error {
objects, _, err := fs.Count(fsrc)
if err != nil {
return err

View File

@ -16,7 +16,7 @@ var commandDefintion = &cobra.Command{
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fdst := cmd.NewFsDst(args)
cmd.Run(true, command, func() error {
cmd.Run(true, false, command, func() error {
return fs.Mkdir(fdst, "")
})
},

View File

@ -34,7 +34,7 @@ into ` + "`dest:path`" + ` then delete the original (if no errors on copy) in
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(2, 2, command, args)
fsrc, fdst := cmd.NewFsSrcDst(args)
cmd.Run(true, command, func() error {
cmd.Run(true, true, command, func() error {
return fs.MoveDir(fdst, fsrc)
})
},

View File

@ -47,7 +47,7 @@ transfer.
cmd.CheckArgs(2, 2, command, args)
fsrc, srcFileName, fdst, dstFileName := cmd.NewFsSrcDstFiles(args)
cmd.Run(true, command, func() error {
cmd.Run(true, true, command, func() error {
if srcFileName == "" {
return fs.MoveDir(fdst, fsrc)
}

View File

@ -21,7 +21,7 @@ you want to selectively delete files.
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fdst := cmd.NewFsDst(args)
cmd.Run(true, command, func() error {
cmd.Run(true, false, command, func() error {
return fs.Purge(fdst)
})
},

View File

@ -19,7 +19,7 @@ objects in it, use purge for that.`,
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fdst := cmd.NewFsDst(args)
cmd.Run(true, command, func() error {
cmd.Run(true, false, command, func() error {
return fs.Rmdir(fdst, "")
})
},

View File

@ -24,7 +24,7 @@ empty directories in.
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fdst := cmd.NewFsDst(args)
cmd.Run(true, command, func() error {
cmd.Run(true, false, command, func() error {
return fs.Rmdirs(fdst)
})
},

View File

@ -22,7 +22,7 @@ is in the same format as the standard sha1sum tool produces.
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fsrc := cmd.NewFsSrc(args)
cmd.Run(false, command, func() error {
cmd.Run(false, false, command, func() error {
return fs.Sha1sum(fsrc, os.Stdout)
})
},

View File

@ -18,7 +18,7 @@ var commandDefintion = &cobra.Command{
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fsrc := cmd.NewFsSrc(args)
cmd.Run(false, command, func() error {
cmd.Run(false, false, command, func() error {
objects, size, err := fs.Count(fsrc)
if err != nil {
return err

View File

@ -36,7 +36,7 @@ go there.
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(2, 2, command, args)
fsrc, fdst := cmd.NewFsSrcDst(args)
cmd.Run(true, command, func() error {
cmd.Run(true, true, command, func() error {
return fs.Sync(fdst, fsrc)
})
},