Skip to content

Commit

Permalink
Satisfied some OCDs
Browse files Browse the repository at this point in the history
  • Loading branch information
empijei committed Feb 28, 2017
1 parent 8d901b9 commit 7be2602
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
31 changes: 13 additions & 18 deletions identities/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package identities
import (
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"math/rand"
Expand All @@ -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, ",")

Expand All @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 7be2602

Please sign in to comment.