From 1b2ffbeca00f90ad4f230f266ccdcd6b5c03d13d Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 11 Oct 2019 16:55:04 +0100 Subject: [PATCH] cmd: fix environment variables not setting command line flags Before this fix quite a lot of the commands were ignoring environment variables intended to set flags. --- cmd/about/about.go | 6 ++- cmd/cat/cat.go | 12 +++--- cmd/check/check.go | 6 ++- cmd/config/config.go | 3 +- cmd/copy/copy.go | 4 +- cmd/copyurl/copyurl.go | 4 +- cmd/cryptcheck/cryptcheck.go | 4 +- cmd/cryptdecode/cryptdecode.go | 4 +- cmd/dedupe/dedupe.go | 4 +- cmd/info/info.go | 14 ++++--- cmd/listremotes/listremotes.go | 4 +- cmd/lsd/lsd.go | 4 +- cmd/lsf/lsf.go | 21 +++++----- cmd/lsjson/lsjson.go | 16 ++++---- cmd/mountlib/mount.go | 34 ++++++++-------- cmd/move/move.go | 6 ++- cmd/rc/rc.go | 14 ++++--- cmd/size/size.go | 4 +- cmd/sync/sync.go | 4 +- cmd/touch/touch.go | 7 ++-- cmd/tree/tree.go | 59 ++++++++++++++-------------- cmd/version/version.go | 5 ++- fs/config/configflags/configflags.go | 2 +- fs/config/flags/flags.go | 4 +- 24 files changed, 140 insertions(+), 105 deletions(-) diff --git a/cmd/about/about.go b/cmd/about/about.go index f9b88793f..854e30e1d 100644 --- a/cmd/about/about.go +++ b/cmd/about/about.go @@ -9,6 +9,7 @@ import ( "github.com/pkg/errors" "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/fs/config/flags" "github.com/spf13/cobra" ) @@ -19,8 +20,9 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().BoolVar(&jsonOutput, "json", false, "Format output as JSON") - commandDefinition.Flags().BoolVar(&fullOutput, "full", false, "Full numbers instead of SI units") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &jsonOutput, "json", "", false, "Format output as JSON") + flags.BoolVarP(cmdFlags, &fullOutput, "full", "", false, "Full numbers instead of SI units") } // printValue formats uv to be output diff --git a/cmd/cat/cat.go b/cmd/cat/cat.go index eded44b3f..46d95a902 100644 --- a/cmd/cat/cat.go +++ b/cmd/cat/cat.go @@ -8,6 +8,7 @@ import ( "os" "github.com/rclone/rclone/cmd" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/operations" "github.com/spf13/cobra" ) @@ -23,11 +24,12 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().Int64VarP(&head, "head", "", head, "Only print the first N characters.") - commandDefinition.Flags().Int64VarP(&tail, "tail", "", tail, "Only print the last N characters.") - commandDefinition.Flags().Int64VarP(&offset, "offset", "", offset, "Start printing at offset N (or from end if -ve).") - commandDefinition.Flags().Int64VarP(&count, "count", "", count, "Only print N characters.") - commandDefinition.Flags().BoolVarP(&discard, "discard", "", discard, "Discard the output instead of printing.") + cmdFlags := commandDefinition.Flags() + flags.Int64VarP(cmdFlags, &head, "head", "", head, "Only print the first N characters.") + flags.Int64VarP(cmdFlags, &tail, "tail", "", tail, "Only print the last N characters.") + flags.Int64VarP(cmdFlags, &offset, "offset", "", offset, "Start printing at offset N (or from end if -ve).") + flags.Int64VarP(cmdFlags, &count, "count", "", count, "Only print N characters.") + flags.BoolVarP(cmdFlags, &discard, "discard", "", discard, "Discard the output instead of printing.") } var commandDefinition = &cobra.Command{ diff --git a/cmd/check/check.go b/cmd/check/check.go index e09a5cc65..6abba2286 100644 --- a/cmd/check/check.go +++ b/cmd/check/check.go @@ -4,6 +4,7 @@ import ( "context" "github.com/rclone/rclone/cmd" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/operations" "github.com/spf13/cobra" ) @@ -16,8 +17,9 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().BoolVarP(&download, "download", "", download, "Check by downloading rather than with hash.") - commandDefinition.Flags().BoolVarP(&oneway, "one-way", "", oneway, "Check one way only, source files must exist on remote") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &download, "download", "", download, "Check by downloading rather than with hash.") + flags.BoolVarP(cmdFlags, &oneway, "one-way", "", oneway, "Check one way only, source files must exist on remote") } var commandDefinition = &cobra.Command{ diff --git a/cmd/config/config.go b/cmd/config/config.go index 2e650e9ea..3e675cc5a 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -11,6 +11,7 @@ import ( "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/config" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/rc" "github.com/spf13/cobra" ) @@ -271,7 +272,7 @@ var ( ) func init() { - configUserInfoCommand.Flags().BoolVar(&jsonOutput, "json", false, "Format output as JSON") + flags.BoolVarP(configUserInfoCommand.Flags(), &jsonOutput, "json", "", false, "Format output as JSON") } var configUserInfoCommand = &cobra.Command{ diff --git a/cmd/copy/copy.go b/cmd/copy/copy.go index 7ee130d20..9b5444105 100644 --- a/cmd/copy/copy.go +++ b/cmd/copy/copy.go @@ -4,6 +4,7 @@ import ( "context" "github.com/rclone/rclone/cmd" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/operations" "github.com/rclone/rclone/fs/sync" "github.com/spf13/cobra" @@ -15,7 +16,8 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().BoolVarP(&createEmptySrcDirs, "create-empty-src-dirs", "", createEmptySrcDirs, "Create empty source dirs on destination after copy") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &createEmptySrcDirs, "create-empty-src-dirs", "", createEmptySrcDirs, "Create empty source dirs on destination after copy") } var commandDefinition = &cobra.Command{ diff --git a/cmd/copyurl/copyurl.go b/cmd/copyurl/copyurl.go index ef9e107c9..21118ba6e 100644 --- a/cmd/copyurl/copyurl.go +++ b/cmd/copyurl/copyurl.go @@ -5,6 +5,7 @@ import ( "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/operations" "github.com/spf13/cobra" ) @@ -15,7 +16,8 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().BoolVarP(&autoFilename, "auto-filename", "a", autoFilename, "Get the file name from the url and use it for destination file path") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &autoFilename, "auto-filename", "a", autoFilename, "Get the file name from the url and use it for destination file path") } var commandDefinition = &cobra.Command{ diff --git a/cmd/cryptcheck/cryptcheck.go b/cmd/cryptcheck/cryptcheck.go index 4e35ec72d..7a64f3453 100644 --- a/cmd/cryptcheck/cryptcheck.go +++ b/cmd/cryptcheck/cryptcheck.go @@ -7,6 +7,7 @@ import ( "github.com/rclone/rclone/backend/crypt" "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/hash" "github.com/rclone/rclone/fs/operations" "github.com/spf13/cobra" @@ -19,7 +20,8 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().BoolVarP(&oneway, "one-way", "", oneway, "Check one way only, source files must exist on destination") + cmdFlag := commandDefinition.Flags() + flags.BoolVarP(cmdFlag, &oneway, "one-way", "", oneway, "Check one way only, source files must exist on destination") } var commandDefinition = &cobra.Command{ diff --git a/cmd/cryptdecode/cryptdecode.go b/cmd/cryptdecode/cryptdecode.go index 6a2c7fd5f..493f9edf6 100644 --- a/cmd/cryptdecode/cryptdecode.go +++ b/cmd/cryptdecode/cryptdecode.go @@ -18,8 +18,8 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - flagSet := commandDefinition.Flags() - flags.BoolVarP(flagSet, &Reverse, "reverse", "", Reverse, "Reverse cryptdecode, encrypts filenames") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &Reverse, "reverse", "", Reverse, "Reverse cryptdecode, encrypts filenames") } var commandDefinition = &cobra.Command{ diff --git a/cmd/dedupe/dedupe.go b/cmd/dedupe/dedupe.go index 762014b43..fbe38f81d 100644 --- a/cmd/dedupe/dedupe.go +++ b/cmd/dedupe/dedupe.go @@ -5,6 +5,7 @@ import ( "log" "github.com/rclone/rclone/cmd" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/operations" "github.com/spf13/cobra" ) @@ -15,7 +16,8 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().VarP(&dedupeMode, "dedupe-mode", "", "Dedupe mode interactive|skip|first|newest|oldest|rename.") + cmdFlag := commandDefinition.Flags() + flags.FVarP(cmdFlag, &dedupeMode, "dedupe-mode", "", "Dedupe mode interactive|skip|first|newest|oldest|rename.") } var commandDefinition = &cobra.Command{ diff --git a/cmd/info/info.go b/cmd/info/info.go index 10bc9953d..ed5691887 100644 --- a/cmd/info/info.go +++ b/cmd/info/info.go @@ -22,6 +22,7 @@ import ( "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd/info/internal" "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/hash" "github.com/rclone/rclone/fs/object" "github.com/rclone/rclone/lib/random" @@ -42,12 +43,13 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().StringVarP(&writeJSON, "write-json", "", "", "Write results to file.") - commandDefinition.Flags().BoolVarP(&checkNormalization, "check-normalization", "", true, "Check UTF-8 Normalization.") - commandDefinition.Flags().BoolVarP(&checkControl, "check-control", "", true, "Check control characters.") - commandDefinition.Flags().DurationVarP(&uploadWait, "upload-wait", "", 0, "Wait after writing a file.") - commandDefinition.Flags().BoolVarP(&checkLength, "check-length", "", true, "Check max filename length.") - commandDefinition.Flags().BoolVarP(&checkStreaming, "check-streaming", "", true, "Check uploads with indeterminate file size.") + cmdFlags := commandDefinition.Flags() + flags.StringVarP(cmdFlags, &writeJSON, "write-json", "", "", "Write results to file.") + flags.BoolVarP(cmdFlags, &checkNormalization, "check-normalization", "", true, "Check UTF-8 Normalization.") + flags.BoolVarP(cmdFlags, &checkControl, "check-control", "", true, "Check control characters.") + flags.DurationVarP(cmdFlags, &uploadWait, "upload-wait", "", 0, "Wait after writing a file.") + flags.BoolVarP(cmdFlags, &checkLength, "check-length", "", true, "Check max filename length.") + flags.BoolVarP(cmdFlags, &checkStreaming, "check-streaming", "", true, "Check uploadxs with indeterminate file size.") } var commandDefinition = &cobra.Command{ diff --git a/cmd/listremotes/listremotes.go b/cmd/listremotes/listremotes.go index 8a442b49f..e41bce10f 100644 --- a/cmd/listremotes/listremotes.go +++ b/cmd/listremotes/listremotes.go @@ -6,6 +6,7 @@ import ( "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/fs/config" + "github.com/rclone/rclone/fs/config/flags" "github.com/spf13/cobra" ) @@ -16,7 +17,8 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().BoolVarP(&listLong, "long", "", listLong, "Show the type as well as names.") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &listLong, "long", "", listLong, "Show the type as well as names.") } var commandDefinition = &cobra.Command{ diff --git a/cmd/lsd/lsd.go b/cmd/lsd/lsd.go index 7130bd7ae..de102e102 100644 --- a/cmd/lsd/lsd.go +++ b/cmd/lsd/lsd.go @@ -7,6 +7,7 @@ import ( "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd/ls/lshelp" "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/operations" "github.com/spf13/cobra" ) @@ -17,7 +18,8 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().BoolVarP(&recurse, "recursive", "R", false, "Recurse into the listing.") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &recurse, "recursive", "R", false, "Recurse into the listing.") } var commandDefinition = &cobra.Command{ diff --git a/cmd/lsf/lsf.go b/cmd/lsf/lsf.go index 4b1358042..bd46734df 100644 --- a/cmd/lsf/lsf.go +++ b/cmd/lsf/lsf.go @@ -10,6 +10,7 @@ import ( "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd/ls/lshelp" "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/hash" "github.com/rclone/rclone/fs/operations" "github.com/spf13/cobra" @@ -29,16 +30,16 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - flags := commandDefinition.Flags() - flags.StringVarP(&format, "format", "F", "p", "Output format - see help for details") - flags.StringVarP(&separator, "separator", "s", ";", "Separator for the items in the format.") - flags.BoolVarP(&dirSlash, "dir-slash", "d", true, "Append a slash to directory names.") - flags.VarP(&hashType, "hash", "", "Use this hash when `h` is used in the format MD5|SHA-1|DropboxHash") - flags.BoolVarP(&filesOnly, "files-only", "", false, "Only list files.") - flags.BoolVarP(&dirsOnly, "dirs-only", "", false, "Only list directories.") - flags.BoolVarP(&csv, "csv", "", false, "Output in CSV format.") - flags.BoolVarP(&absolute, "absolute", "", false, "Put a leading / in front of path names.") - commandDefinition.Flags().BoolVarP(&recurse, "recursive", "R", false, "Recurse into the listing.") + cmdFlags := commandDefinition.Flags() + flags.StringVarP(cmdFlags, &format, "format", "F", "p", "Output format - see help for details") + flags.StringVarP(cmdFlags, &separator, "separator", "s", ";", "Separator for the items in the format.") + flags.BoolVarP(cmdFlags, &dirSlash, "dir-slash", "d", true, "Append a slash to directory names.") + flags.FVarP(cmdFlags, &hashType, "hash", "", "Use this hash when `h` is used in the format MD5|SHA-1|DropboxHash") + flags.BoolVarP(cmdFlags, &filesOnly, "files-only", "", false, "Only list files.") + flags.BoolVarP(cmdFlags, &dirsOnly, "dirs-only", "", false, "Only list directories.") + flags.BoolVarP(cmdFlags, &csv, "csv", "", false, "Output in CSV format.") + flags.BoolVarP(cmdFlags, &absolute, "absolute", "", false, "Put a leading / in front of path names.") + flags.BoolVarP(cmdFlags, &recurse, "recursive", "R", false, "Recurse into the listing.") } var commandDefinition = &cobra.Command{ diff --git a/cmd/lsjson/lsjson.go b/cmd/lsjson/lsjson.go index 082a65d51..aecdc2e99 100644 --- a/cmd/lsjson/lsjson.go +++ b/cmd/lsjson/lsjson.go @@ -9,6 +9,7 @@ import ( "github.com/pkg/errors" "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd/ls/lshelp" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/operations" "github.com/spf13/cobra" ) @@ -19,13 +20,14 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().BoolVarP(&opt.Recurse, "recursive", "R", false, "Recurse into the listing.") - commandDefinition.Flags().BoolVarP(&opt.ShowHash, "hash", "", false, "Include hashes in the output (may take longer).") - commandDefinition.Flags().BoolVarP(&opt.NoModTime, "no-modtime", "", false, "Don't read the modification time (can speed things up).") - commandDefinition.Flags().BoolVarP(&opt.ShowEncrypted, "encrypted", "M", false, "Show the encrypted names.") - commandDefinition.Flags().BoolVarP(&opt.ShowOrigIDs, "original", "", false, "Show the ID of the underlying Object.") - commandDefinition.Flags().BoolVarP(&opt.FilesOnly, "files-only", "", false, "Show only files in the listing.") - commandDefinition.Flags().BoolVarP(&opt.DirsOnly, "dirs-only", "", false, "Show only directories in the listing.") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &opt.Recurse, "recursive", "R", false, "Recurse into the listing.") + flags.BoolVarP(cmdFlags, &opt.ShowHash, "hash", "", false, "Include hashes in the output (may take longer).") + flags.BoolVarP(cmdFlags, &opt.NoModTime, "no-modtime", "", false, "Don't read the modification time (can speed things up).") + flags.BoolVarP(cmdFlags, &opt.ShowEncrypted, "encrypted", "M", false, "Show the encrypted names.") + flags.BoolVarP(cmdFlags, &opt.ShowOrigIDs, "original", "", false, "Show the ID of the underlying Object.") + flags.BoolVarP(cmdFlags, &opt.FilesOnly, "files-only", "", false, "Show only files in the listing.") + flags.BoolVarP(cmdFlags, &opt.DirsOnly, "dirs-only", "", false, "Show only directories in the listing.") } var commandDefinition = &cobra.Command{ diff --git a/cmd/mountlib/mount.go b/cmd/mountlib/mount.go index 23b283edc..9d0e3d41a 100644 --- a/cmd/mountlib/mount.go +++ b/cmd/mountlib/mount.go @@ -298,29 +298,29 @@ be copied to the vfs cache before opening with --vfs-cache-mode full. cmd.Root.AddCommand(commandDefinition) // Add flags - flagSet := commandDefinition.Flags() - flags.BoolVarP(flagSet, &DebugFUSE, "debug-fuse", "", DebugFUSE, "Debug the FUSE internals - needs -v.") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &DebugFUSE, "debug-fuse", "", DebugFUSE, "Debug the FUSE internals - needs -v.") // mount options - flags.BoolVarP(flagSet, &AllowNonEmpty, "allow-non-empty", "", AllowNonEmpty, "Allow mounting over a non-empty directory.") - flags.BoolVarP(flagSet, &AllowRoot, "allow-root", "", AllowRoot, "Allow access to root user.") - flags.BoolVarP(flagSet, &AllowOther, "allow-other", "", AllowOther, "Allow access to other users.") - flags.BoolVarP(flagSet, &DefaultPermissions, "default-permissions", "", DefaultPermissions, "Makes kernel enforce access control based on the file mode.") - flags.BoolVarP(flagSet, &WritebackCache, "write-back-cache", "", WritebackCache, "Makes kernel buffer writes before sending them to rclone. Without this, writethrough caching is used.") - flags.FVarP(flagSet, &MaxReadAhead, "max-read-ahead", "", "The number of bytes that can be prefetched for sequential reads.") - flags.DurationVarP(flagSet, &AttrTimeout, "attr-timeout", "", AttrTimeout, "Time for which file/directory attributes are cached.") - flags.StringArrayVarP(flagSet, &ExtraOptions, "option", "o", []string{}, "Option for libfuse/WinFsp. Repeat if required.") - flags.StringArrayVarP(flagSet, &ExtraFlags, "fuse-flag", "", []string{}, "Flags or arguments to be passed direct to libfuse/WinFsp. Repeat if required.") - flags.BoolVarP(flagSet, &Daemon, "daemon", "", Daemon, "Run mount as a daemon (background mode).") - flags.StringVarP(flagSet, &VolumeName, "volname", "", VolumeName, "Set the volume name (not supported by all OSes).") - flags.DurationVarP(flagSet, &DaemonTimeout, "daemon-timeout", "", DaemonTimeout, "Time limit for rclone to respond to kernel (not supported by all OSes).") + flags.BoolVarP(cmdFlags, &AllowNonEmpty, "allow-non-empty", "", AllowNonEmpty, "Allow mounting over a non-empty directory.") + flags.BoolVarP(cmdFlags, &AllowRoot, "allow-root", "", AllowRoot, "Allow access to root user.") + flags.BoolVarP(cmdFlags, &AllowOther, "allow-other", "", AllowOther, "Allow access to other users.") + flags.BoolVarP(cmdFlags, &DefaultPermissions, "default-permissions", "", DefaultPermissions, "Makes kernel enforce access control based on the file mode.") + flags.BoolVarP(cmdFlags, &WritebackCache, "write-back-cache", "", WritebackCache, "Makes kernel buffer writes before sending them to rclone. Without this, writethrough caching is used.") + flags.FVarP(cmdFlags, &MaxReadAhead, "max-read-ahead", "", "The number of bytes that can be prefetched for sequential reads.") + flags.DurationVarP(cmdFlags, &AttrTimeout, "attr-timeout", "", AttrTimeout, "Time for which file/directory attributes are cached.") + flags.StringArrayVarP(cmdFlags, &ExtraOptions, "option", "o", []string{}, "Option for libfuse/WinFsp. Repeat if required.") + flags.StringArrayVarP(cmdFlags, &ExtraFlags, "fuse-flag", "", []string{}, "Flags or arguments to be passed direct to libfuse/WinFsp. Repeat if required.") + flags.BoolVarP(cmdFlags, &Daemon, "daemon", "", Daemon, "Run mount as a daemon (background mode).") + flags.StringVarP(cmdFlags, &VolumeName, "volname", "", VolumeName, "Set the volume name (not supported by all OSes).") + flags.DurationVarP(cmdFlags, &DaemonTimeout, "daemon-timeout", "", DaemonTimeout, "Time limit for rclone to respond to kernel (not supported by all OSes).") if runtime.GOOS == "darwin" { - flags.BoolVarP(flagSet, &NoAppleDouble, "noappledouble", "", NoAppleDouble, "Sets the OSXFUSE option noappledouble.") - flags.BoolVarP(flagSet, &NoAppleXattr, "noapplexattr", "", NoAppleXattr, "Sets the OSXFUSE option noapplexattr.") + flags.BoolVarP(cmdFlags, &NoAppleDouble, "noappledouble", "", NoAppleDouble, "Sets the OSXFUSE option noappledouble.") + flags.BoolVarP(cmdFlags, &NoAppleXattr, "noapplexattr", "", NoAppleXattr, "Sets the OSXFUSE option noapplexattr.") } // Add in the generic flags - vfsflags.AddFlags(flagSet) + vfsflags.AddFlags(cmdFlags) return commandDefinition } diff --git a/cmd/move/move.go b/cmd/move/move.go index f214aaa09..80f96c201 100644 --- a/cmd/move/move.go +++ b/cmd/move/move.go @@ -4,6 +4,7 @@ import ( "context" "github.com/rclone/rclone/cmd" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/operations" "github.com/rclone/rclone/fs/sync" "github.com/spf13/cobra" @@ -17,8 +18,9 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().BoolVarP(&deleteEmptySrcDirs, "delete-empty-src-dirs", "", deleteEmptySrcDirs, "Delete empty source dirs after move") - commandDefinition.Flags().BoolVarP(&createEmptySrcDirs, "create-empty-src-dirs", "", createEmptySrcDirs, "Create empty source dirs on destination after move") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &deleteEmptySrcDirs, "delete-empty-src-dirs", "", deleteEmptySrcDirs, "Delete empty source dirs after move") + flags.BoolVarP(cmdFlags, &createEmptySrcDirs, "create-empty-src-dirs", "", createEmptySrcDirs, "Create empty source dirs on destination after move") } var commandDefinition = &cobra.Command{ diff --git a/cmd/rc/rc.go b/cmd/rc/rc.go index 7960df700..50bb5540d 100644 --- a/cmd/rc/rc.go +++ b/cmd/rc/rc.go @@ -13,6 +13,7 @@ import ( "github.com/pkg/errors" "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/fshttp" "github.com/rclone/rclone/fs/rc" "github.com/spf13/cobra" @@ -30,12 +31,13 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().BoolVarP(&noOutput, "no-output", "", noOutput, "If set don't output the JSON result.") - commandDefinition.Flags().StringVarP(&url, "url", "", url, "URL to connect to rclone remote control.") - commandDefinition.Flags().StringVarP(&jsonInput, "json", "", jsonInput, "Input JSON - use instead of key=value args.") - commandDefinition.Flags().StringVarP(&authUser, "user", "", "", "Username to use to rclone remote control.") - commandDefinition.Flags().StringVarP(&authPass, "pass", "", "", "Password to use to connect to rclone remote control.") - commandDefinition.Flags().BoolVarP(&loopback, "loopback", "", false, "If set connect to this rclone instance not via HTTP.") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &noOutput, "no-output", "", noOutput, "If set don't output the JSON result.") + flags.StringVarP(cmdFlags, &url, "url", "", url, "URL to connect to rclone remote control.") + flags.StringVarP(cmdFlags, &jsonInput, "json", "", jsonInput, "Input JSON - use instead of key=value args.") + flags.StringVarP(cmdFlags, &authUser, "user", "", "", "Username to use to rclone remote control.") + flags.StringVarP(cmdFlags, &authPass, "pass", "", "", "Password to use to connect to rclone remote control.") + flags.BoolVarP(cmdFlags, &loopback, "loopback", "", false, "If set connect to this rclone instance not via HTTP.") } var commandDefinition = &cobra.Command{ diff --git a/cmd/size/size.go b/cmd/size/size.go index cffeced31..2660a83c4 100644 --- a/cmd/size/size.go +++ b/cmd/size/size.go @@ -8,6 +8,7 @@ import ( "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/operations" "github.com/spf13/cobra" ) @@ -16,7 +17,8 @@ var jsonOutput bool func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().BoolVar(&jsonOutput, "json", false, "format output as JSON") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &jsonOutput, "json", "", false, "format output as JSON") } var commandDefinition = &cobra.Command{ diff --git a/cmd/sync/sync.go b/cmd/sync/sync.go index ade6eb741..feb593be1 100644 --- a/cmd/sync/sync.go +++ b/cmd/sync/sync.go @@ -4,6 +4,7 @@ import ( "context" "github.com/rclone/rclone/cmd" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/operations" "github.com/rclone/rclone/fs/sync" "github.com/spf13/cobra" @@ -15,7 +16,8 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - commandDefinition.Flags().BoolVarP(&createEmptySrcDirs, "create-empty-src-dirs", "", createEmptySrcDirs, "Create empty source dirs on destination after sync") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &createEmptySrcDirs, "create-empty-src-dirs", "", createEmptySrcDirs, "Create empty source dirs on destination after sync") } var commandDefinition = &cobra.Command{ diff --git a/cmd/touch/touch.go b/cmd/touch/touch.go index a91ab23ea..c4f2caf69 100644 --- a/cmd/touch/touch.go +++ b/cmd/touch/touch.go @@ -8,6 +8,7 @@ import ( "github.com/pkg/errors" "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/object" "github.com/spf13/cobra" ) @@ -22,9 +23,9 @@ const layoutDateWithTime = "2006-01-02T15:04:05" func init() { cmd.Root.AddCommand(commandDefinition) - flags := commandDefinition.Flags() - flags.BoolVarP(¬CreateNewFile, "no-create", "C", false, "Do not create the file if it does not exist.") - flags.StringVarP(&timeAsArgument, "timestamp", "t", "", "Change the modification times to the specified time instead of the current time of day. The argument is of the form 'YYMMDD' (ex. 17.10.30) or 'YYYY-MM-DDTHH:MM:SS' (ex. 2006-01-02T15:04:05)") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, ¬CreateNewFile, "no-create", "C", false, "Do not create the file if it does not exist.") + flags.StringVarP(cmdFlags, &timeAsArgument, "timestamp", "t", "", "Change the modification times to the specified time instead of the current time of day. The argument is of the form 'YYMMDD' (ex. 17.10.30) or 'YYYY-MM-DDTHH:MM:SS' (ex. 2006-01-02T15:04:05)") } var commandDefinition = &cobra.Command{ diff --git a/cmd/tree/tree.go b/cmd/tree/tree.go index 43a0cbf51..6babdc3c6 100644 --- a/cmd/tree/tree.go +++ b/cmd/tree/tree.go @@ -14,6 +14,7 @@ import ( "github.com/pkg/errors" "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/dirtree" "github.com/rclone/rclone/fs/log" "github.com/rclone/rclone/fs/walk" @@ -29,39 +30,39 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - flags := commandDefinition.Flags() + cmdFlags := commandDefinition.Flags() // List - flags.BoolVarP(&opts.All, "all", "a", false, "All files are listed (list . files too).") - flags.BoolVarP(&opts.DirsOnly, "dirs-only", "d", false, "List directories only.") - flags.BoolVarP(&opts.FullPath, "full-path", "", false, "Print the full path prefix for each file.") - //flags.BoolVarP(&opts.IgnoreCase, "ignore-case", "", false, "Ignore case when pattern matching.") - flags.BoolVarP(&noReport, "noreport", "", false, "Turn off file/directory count at end of tree listing.") - // flags.BoolVarP(&opts.FollowLink, "follow", "l", false, "Follow symbolic links like directories.") - flags.IntVarP(&opts.DeepLevel, "level", "", 0, "Descend only level directories deep.") - // flags.StringVarP(&opts.Pattern, "pattern", "P", "", "List only those files that match the pattern given.") - // flags.StringVarP(&opts.IPattern, "exclude", "", "", "Do not list files that match the given pattern.") - flags.StringVarP(&outFileName, "output", "o", "", "Output to file instead of stdout.") + flags.BoolVarP(cmdFlags, &opts.All, "all", "a", false, "All files are listed (list . files too).") + flags.BoolVarP(cmdFlags, &opts.DirsOnly, "dirs-only", "d", false, "List directories only.") + flags.BoolVarP(cmdFlags, &opts.FullPath, "full-path", "", false, "Print the full path prefix for each file.") + //flags.BoolVarP(cmdFlags, &opts.IgnoreCase, "ignore-case", "", false, "Ignore case when pattern matching.") + flags.BoolVarP(cmdFlags, &noReport, "noreport", "", false, "Turn off file/directory count at end of tree listing.") + // flags.BoolVarP(cmdFlags, &opts.FollowLink, "follow", "l", false, "Follow symbolic links like directories.") + flags.IntVarP(cmdFlags, &opts.DeepLevel, "level", "", 0, "Descend only level directories deep.") + // flags.StringVarP(cmdFlags, &opts.Pattern, "pattern", "P", "", "List only those files that match the pattern given.") + // flags.StringVarP(cmdFlags, &opts.IPattern, "exclude", "", "", "Do not list files that match the given pattern.") + flags.StringVarP(cmdFlags, &outFileName, "output", "o", "", "Output to file instead of stdout.") // Files - flags.BoolVarP(&opts.ByteSize, "size", "s", false, "Print the size in bytes of each file.") - flags.BoolVarP(&opts.UnitSize, "human", "", false, "Print the size in a more human readable way.") - flags.BoolVarP(&opts.FileMode, "protections", "p", false, "Print the protections for each file.") - // flags.BoolVarP(&opts.ShowUid, "uid", "", false, "Displays file owner or UID number.") - // flags.BoolVarP(&opts.ShowGid, "gid", "", false, "Displays file group owner or GID number.") - flags.BoolVarP(&opts.Quotes, "quote", "Q", false, "Quote filenames with double quotes.") - flags.BoolVarP(&opts.LastMod, "modtime", "D", false, "Print the date of last modification.") - // flags.BoolVarP(&opts.Inodes, "inodes", "", false, "Print inode number of each file.") - // flags.BoolVarP(&opts.Device, "device", "", false, "Print device ID number to which each file belongs.") + flags.BoolVarP(cmdFlags, &opts.ByteSize, "size", "s", false, "Print the size in bytes of each file.") + flags.BoolVarP(cmdFlags, &opts.UnitSize, "human", "", false, "Print the size in a more human readable way.") + flags.BoolVarP(cmdFlags, &opts.FileMode, "protections", "p", false, "Print the protections for each file.") + // flags.BoolVarP(cmdFlags, &opts.ShowUid, "uid", "", false, "Displays file owner or UID number.") + // flags.BoolVarP(cmdFlags, &opts.ShowGid, "gid", "", false, "Displays file group owner or GID number.") + flags.BoolVarP(cmdFlags, &opts.Quotes, "quote", "Q", false, "Quote filenames with double quotes.") + flags.BoolVarP(cmdFlags, &opts.LastMod, "modtime", "D", false, "Print the date of last modification.") + // flags.BoolVarP(cmdFlags, &opts.Inodes, "inodes", "", false, "Print inode number of each file.") + // flags.BoolVarP(cmdFlags, &opts.Device, "device", "", false, "Print device ID number to which each file belongs.") // Sort - flags.BoolVarP(&opts.NoSort, "unsorted", "U", false, "Leave files unsorted.") - flags.BoolVarP(&opts.VerSort, "version", "", false, "Sort files alphanumerically by version.") - flags.BoolVarP(&opts.ModSort, "sort-modtime", "t", false, "Sort files by last modification time.") - flags.BoolVarP(&opts.CTimeSort, "sort-ctime", "", false, "Sort files by last status change time.") - flags.BoolVarP(&opts.ReverSort, "sort-reverse", "r", false, "Reverse the order of the sort.") - flags.BoolVarP(&opts.DirSort, "dirsfirst", "", false, "List directories before files (-U disables).") - flags.StringVarP(&sort, "sort", "", "", "Select sort: name,version,size,mtime,ctime.") + flags.BoolVarP(cmdFlags, &opts.NoSort, "unsorted", "U", false, "Leave files unsorted.") + flags.BoolVarP(cmdFlags, &opts.VerSort, "version", "", false, "Sort files alphanumerically by version.") + flags.BoolVarP(cmdFlags, &opts.ModSort, "sort-modtime", "t", false, "Sort files by last modification time.") + flags.BoolVarP(cmdFlags, &opts.CTimeSort, "sort-ctime", "", false, "Sort files by last status change time.") + flags.BoolVarP(cmdFlags, &opts.ReverSort, "sort-reverse", "r", false, "Reverse the order of the sort.") + flags.BoolVarP(cmdFlags, &opts.DirSort, "dirsfirst", "", false, "List directories before files (-U disables).") + flags.StringVarP(cmdFlags, &sort, "sort", "", "", "Select sort: name,version,size,mtime,ctime.") // Graphics - flags.BoolVarP(&opts.NoIndent, "noindent", "i", false, "Don't print indentation lines.") - flags.BoolVarP(&opts.Colorize, "color", "C", false, "Turn colorization on always.") + flags.BoolVarP(cmdFlags, &opts.NoIndent, "noindent", "i", false, "Don't print indentation lines.") + flags.BoolVarP(cmdFlags, &opts.Colorize, "color", "C", false, "Turn colorization on always.") } var commandDefinition = &cobra.Command{ diff --git a/cmd/version/version.go b/cmd/version/version.go index f30de5a62..a98f459de 100644 --- a/cmd/version/version.go +++ b/cmd/version/version.go @@ -10,6 +10,7 @@ import ( "github.com/pkg/errors" "github.com/rclone/rclone/cmd" "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/version" "github.com/spf13/cobra" ) @@ -20,8 +21,8 @@ var ( func init() { cmd.Root.AddCommand(commandDefinition) - flags := commandDefinition.Flags() - flags.BoolVarP(&check, "check", "", false, "Check for new version.") + cmdFlags := commandDefinition.Flags() + flags.BoolVarP(cmdFlags, &check, "check", "", false, "Check for new version.") } var commandDefinition = &cobra.Command{ diff --git a/fs/config/configflags/configflags.go b/fs/config/configflags/configflags.go index 8ada95e07..49e0d271b 100644 --- a/fs/config/configflags/configflags.go +++ b/fs/config/configflags/configflags.go @@ -57,7 +57,7 @@ func AddFlags(flagSet *pflag.FlagSet) { flags.BoolVarP(flagSet, &deleteBefore, "delete-before", "", false, "When synchronizing, delete files on destination before transferring") flags.BoolVarP(flagSet, &deleteDuring, "delete-during", "", false, "When synchronizing, delete files during transfer") flags.BoolVarP(flagSet, &deleteAfter, "delete-after", "", false, "When synchronizing, delete files on destination after transferring (default)") - flags.IntVar64P(flagSet, &fs.Config.MaxDelete, "max-delete", "", -1, "When synchronizing, limit the number of deletes") + flags.Int64VarP(flagSet, &fs.Config.MaxDelete, "max-delete", "", -1, "When synchronizing, limit the number of deletes") flags.BoolVarP(flagSet, &fs.Config.TrackRenames, "track-renames", "", fs.Config.TrackRenames, "When synchronizing, track file renames and do a server side move if possible") flags.IntVarP(flagSet, &fs.Config.LowLevelRetries, "low-level-retries", "", fs.Config.LowLevelRetries, "Number of low level retries to do.") flags.BoolVarP(flagSet, &fs.Config.UpdateOlder, "update", "u", fs.Config.UpdateOlder, "Skip files that are newer on the destination.") diff --git a/fs/config/flags/flags.go b/fs/config/flags/flags.go index dd1075c79..bd27810fa 100644 --- a/fs/config/flags/flags.go +++ b/fs/config/flags/flags.go @@ -82,10 +82,10 @@ func Int64P(name, shorthand string, value int64, usage string) (out *int64) { return out } -// IntVar64P defines a flag which can be overridden by an environment variable +// Int64VarP defines a flag which can be overridden by an environment variable // // It is a thin wrapper around pflag.Int64VarP -func IntVar64P(flags *pflag.FlagSet, p *int64, name, shorthand string, value int64, usage string) { +func Int64VarP(flags *pflag.FlagSet, p *int64, name, shorthand string, value int64, usage string) { flags.Int64VarP(p, name, shorthand, value, usage) setDefaultFromEnv(flags, name) }