diff --git a/identities/generator.go b/identities/generator.go index 8da4212..275d459 100644 --- a/identities/generator.go +++ b/identities/generator.go @@ -3,7 +3,6 @@ package identities import ( "encoding/json" "errors" - "flag" "fmt" "io" "math/rand" @@ -19,30 +18,28 @@ func MainModule(args map[string]interface{}, out io.Writer) { fmt.Fprintln(out, "Error occurred: ", r) } }() + dt_fmt := args["dt_fmt"].(string) minage := args["minage"].(int) maxage := args["maxage"].(int) - n := args["n"].(int) - dateformat := args["dateformat"].(string) + number := args["number"].(int) format := args["format"].(string) - filter := args["filter"].(string) + fields := args["fields"].(string) - if minage >= maxage || n <= 0 { - flag.PrintDefaults() + if minage >= maxage || number <= 0 { + panic("'minage' should be less than or equal to 'maxage'") } - if filter != "all" { - tmp := strings.Split(filter, ",") + if fields != "all" { + tmp := strings.Split(fields, ",") err := SetFilter(tmp) if err != nil { - fmt.Println(err) - flag.PrintDefaults() + panic(err) } } - LocalizDate = NewDateFormat(dateformat) - people, err := RandomPeople(minage, maxage, n) + LocalizDate = NewDateFormat(dt_fmt) + people, err := RandomPeople(minage, maxage, number) if err != nil { - fmt.Println(err) - return + panic(err) } tmpArray := strings.Split(format, ",") @@ -60,16 +57,14 @@ func MainModule(args map[string]interface{}, out io.Writer) { case "json": b, err := json.MarshalIndent(&people, "", "\t") if err != nil { - fmt.Println("error:", err) - return + panic(err) } _, _ = out.Write(b) fmt.Fprintln(out) case "csv": err := MarshalCSV(people, out) if err != nil { - fmt.Println("error:", err) - return + panic(err) } fmt.Fprintln(out) default: diff --git a/main.go b/main.go index 65e5331..d4fb4f1 100644 --- a/main.go +++ b/main.go @@ -9,20 +9,20 @@ import ( var minage = flag.Int("minage", 25, "The minimum age for random people generation. Must be positive and less than maxage.") var maxage = flag.Int("maxage", 55, "The maximum age for random people generation. Must be positive and more than minage.") -var n = flag.Int("n", 1, "The amount of random people to generate. Must be positive.") -var dateformat = flag.String("dateformat", "eu", "The format of the dates. Supports: 'eu','us','ja'") +var number = flag.Int("number", 1, "The amount of random people to generate. Must be positive.") +var dt_fmt = flag.String("dt_fmt", "eu", "The format of the dates. Supports: 'eu','us','ja'") var format = flag.String("format", "human", "The comma separated list of formats for the output. Supports: 'json', 'csv', 'human'") -var filter = flag.String("fields", "all", "The comma separated list of fields to print. Use 'all' to print all of them") +var fields = flag.String("fields", "all", "The comma separated list of fields to print. Use 'all' to print all of them") func main() { flag.Parse() args := make(map[string]interface{}) + args["dt_fmt"] = *dt_fmt args["minage"] = *minage args["maxage"] = *maxage - args["n"] = *n - args["dateformat"] = *dateformat + args["number"] = *number args["format"] = *format - args["filter"] = *filter + args["fields"] = *fields identities.MainModule(args, os.Stdout) }