diff --git a/cmd/test/makefiles/makefiles.go b/cmd/test/makefiles/makefiles.go index 08d1e3ccd..0771ec084 100644 --- a/cmd/test/makefiles/makefiles.go +++ b/cmd/test/makefiles/makefiles.go @@ -17,6 +17,7 @@ import ( "github.com/rclone/rclone/lib/file" "github.com/rclone/rclone/lib/random" "github.com/spf13/cobra" + "github.com/spf13/pflag" ) var ( @@ -38,28 +39,40 @@ var ( ) func init() { - test.Command.AddCommand(commandDefinition) - cmdFlags := commandDefinition.Flags() - flags.IntVarP(cmdFlags, &numberOfFiles, "files", "", numberOfFiles, "Number of files to create") - flags.IntVarP(cmdFlags, &averageFilesPerDirectory, "files-per-directory", "", averageFilesPerDirectory, "Average number of files per directory") - flags.IntVarP(cmdFlags, &maxDepth, "max-depth", "", maxDepth, "Maximum depth of directory hierarchy") - flags.FVarP(cmdFlags, &minFileSize, "min-file-size", "", "Minimum size of file to create") - flags.FVarP(cmdFlags, &maxFileSize, "max-file-size", "", "Maximum size of files to create") - flags.IntVarP(cmdFlags, &minFileNameLength, "min-name-length", "", minFileNameLength, "Minimum size of file names") - flags.IntVarP(cmdFlags, &maxFileNameLength, "max-name-length", "", maxFileNameLength, "Maximum size of file names") - flags.Int64VarP(cmdFlags, &seed, "seed", "", seed, "Seed for the random number generator (0 for random)") + test.Command.AddCommand(makefilesCmd) + makefilesFlags := makefilesCmd.Flags() + flags.IntVarP(makefilesFlags, &numberOfFiles, "files", "", numberOfFiles, "Number of files to create") + flags.IntVarP(makefilesFlags, &averageFilesPerDirectory, "files-per-directory", "", averageFilesPerDirectory, "Average number of files per directory") + flags.IntVarP(makefilesFlags, &maxDepth, "max-depth", "", maxDepth, "Maximum depth of directory hierarchy") + flags.FVarP(makefilesFlags, &minFileSize, "min-file-size", "", "Minimum size of file to create") + flags.FVarP(makefilesFlags, &maxFileSize, "max-file-size", "", "Maximum size of files to create") + flags.IntVarP(makefilesFlags, &minFileNameLength, "min-name-length", "", minFileNameLength, "Minimum size of file names") + flags.IntVarP(makefilesFlags, &maxFileNameLength, "max-name-length", "", maxFileNameLength, "Maximum size of file names") + + test.Command.AddCommand(makefileCmd) + makefileFlags := makefileCmd.Flags() + + // Common flags to makefiles and makefile + for _, f := range []*pflag.FlagSet{makefilesFlags, makefileFlags} { + flags.Int64VarP(f, &seed, "seed", "", seed, "Seed for the random number generator (0 for random)") + } } -var commandDefinition = &cobra.Command{ +// common initialisation for makefiles and makefile +func commonInit() { + if seed == 0 { + seed = time.Now().UnixNano() + fs.Logf(nil, "Using random seed = %d", seed) + } + randSource = rand.New(rand.NewSource(seed)) +} + +var makefilesCmd = &cobra.Command{ Use: "makefiles