From 43c530922aabe0ca08d490e790aeec0f64cdc6c3 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 15 Dec 2016 17:40:17 +0000 Subject: [PATCH] Restore ability for any command to show stats by adding --stats flag Make default for `mount` command not to show stats - this can be re-enabled by adding a `--stats` parameter. --- cmd/cmd.go | 12 ++++++++++++ cmd/mount/mount.go | 8 +++++--- docs/content/docs.md | 8 +++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 23ee116f2..b50b7ecbe 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -224,10 +224,22 @@ func NewFsDst(args []string) fs.Fs { return fdst } +// ShowStats returns true if the user added a `--stats` flag to the command line. +// +// This is called by Run to override the default value of the +// showStats passed in. +func ShowStats() bool { + statsIntervalFlag := pflag.Lookup("stats") + return statsIntervalFlag != nil && statsIntervalFlag.Changed +} + // Run the function with stats and retries if required func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) { var err error var stopStats chan struct{} + if !showStats && ShowStats() { + showStats = true + } if showStats { stopStats = StartStats() } diff --git a/cmd/mount/mount.go b/cmd/mount/mount.go index bd118ded1..1fb0337e2 100644 --- a/cmd/mount/mount.go +++ b/cmd/mount/mount.go @@ -147,9 +147,11 @@ func Mount(f fs.Fs, mountpoint string) error { dirPerms = 0777 &^ os.FileMode(umask) filePerms = 0666 &^ os.FileMode(umask) - // Show stats - stopStats := cmd.StartStats() - defer close(stopStats) + // Show stats if the user has specifically requested them + if cmd.ShowStats() { + stopStats := cmd.StartStats() + defer close(stopStats) + } // Mount it errChan, err := mount(f, mountpoint) diff --git a/docs/content/docs.md b/docs/content/docs.md index 58499a376..4064c633b 100644 --- a/docs/content/docs.md +++ b/docs/content/docs.md @@ -390,12 +390,18 @@ modification times in the same way as rclone. ### --stats=TIME ### -Rclone will print stats at regular intervals to show its progress. +Commands which transfer data (`sync`, `copy`, `copyto`, `move`, +`moveto`) will print data transfer stats at regular intervals to show +their progress. This sets the interval. The default is `1m`. Use 0 to disable. +If you set the stats interval then all command can show stats. This +can be useful when running other commands, `check` or `mount` for +example. + ### --stats-unit=bits|bytes ### By default data transfer rates will be printed in bytes/second.