package main

import (
	"fmt"
	"math/rand"
	"os"
	"path/filepath"
	"time"
)

func main() {

	length, lines, pattern, help, err := ParseArgs(os.Args[1:])

	if err != nil {
		_, _ = os.Stderr.WriteString(fmt.Sprintf("error: %v\n", err))
	}

	if help {
		_, _ = os.Stderr.WriteString(fmt.Sprintf("%s [-s] [-h] [<range>]\n"+
			" -s value \tlength or size  (default: 30x10)\n"+
			" -h --help\tthis help text\n"+
			" <range>  \tcharacter range (default: a-zA-Z0-9)\n"+
			"          \t  0-9a-f      \thexadecimal characters\n"+
			"          \t  aab         \tcharacter list with custom entropy\n"+
			"          \t  {128}-{255}a\tcharacters of upper ASCII table half and \"a\"", filepath.Base(os.Args[0])))
		return
	}

	bytes := ParseRange(pattern)

	rand.Seed(time.Now().UTC().UnixNano())

	for i := 0; i < lines; i++ {

		Random(length, bytes, func(bytes []byte) {
			_, _ = os.Stdout.Write(bytes)
		})

		_, _ = os.Stdout.Write([]byte{'\n'})

	}

}