Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion random/files/random-files/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ Note: Specifying the same seed will produce the same results.

### Acknowledgments

Credit to Juan Benet as the author of [`go-random-files`](https://github.com/jbenet/go-random-files) from which this code was derived.
Credit to [Juan Benet](https://github.com/jbenet) as the author of [`go-random-files`](https://github.com/jbenet/go-random-files) from which this code was derived.
22 changes: 15 additions & 7 deletions random/files/random-files/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import (
)

func main() {
var usage = `usage: %s [options] <path>...
Write a random filesystem hierarchy to each <path>
var usage = `NAME
%s - Write a random filesystem hierarchy to each <path>

Options:
USAGE
%s [options] <path>...

OPTIONS:
`
flag.Usage = func() {
fmt.Fprintf(os.Stderr, usage, os.Args[0])
cmd := os.Args[0]
fmt.Fprintf(os.Stderr, usage, cmd, cmd)
flag.PrintDefaults()
}

Expand All @@ -31,9 +35,9 @@ Options:
flag.Int64Var(&cfg.FileSize, "filesize", cfg.FileSize, "bytes of random data in each file")
flag.IntVar(&cfg.Dirs, "dirs", cfg.Dirs, "number of subdirectories at each depth")
flag.IntVar(&cfg.Files, "files", cfg.Files, "number of files at each depth")
flag.BoolVar(&cfg.RandomDirs, "random-dirs", cfg.RandomDirs, "randomize number of subdirectories, from 1 to -Dirs")
flag.BoolVar(&cfg.RandomFiles, "random-files", cfg.RandomFiles, "randomize number of files, from 1 to -Files")
flag.BoolVar(&cfg.RandomSize, "random-size", cfg.RandomSize, "randomize file size, from 1 to -FileSize")
flag.BoolVar(&cfg.RandomDirs, "random-dirs", cfg.RandomDirs, "randomize number of subdirectories, from 1 to -dirs")
flag.BoolVar(&cfg.RandomFiles, "random-files", cfg.RandomFiles, "randomize number of files, from 1 to -files")
flag.BoolVar(&cfg.RandomSize, "random-size", cfg.RandomSize, "randomize file size, from 1 to -filesize")
flag.Int64Var(&cfg.Seed, "seed", cfg.Seed, "random seed, 0 for current time")
flag.Parse()

Expand All @@ -46,6 +50,10 @@ Options:
err := files.Create(cfg, paths...)
if err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
if len(paths) < 1 {
fmt.Fprintln(os.Stderr)
flag.Usage()
}
os.Exit(1)
}
}