| 29 | } |
| 30 | |
| 31 | func main() { |
| 32 | flag.Parse() |
| 33 | args := flag.Args() |
| 34 | |
| 35 | var print func(ksuid.KSUID) |
| 36 | switch format { |
| 37 | case "string": |
| 38 | print = printString |
| 39 | case "inspect": |
| 40 | print = printInspect |
| 41 | case "time": |
| 42 | print = printTime |
| 43 | case "timestamp": |
| 44 | print = printTimestamp |
| 45 | case "payload": |
| 46 | print = printPayload |
| 47 | case "raw": |
| 48 | print = printRaw |
| 49 | case "template": |
| 50 | print = printTemplate |
| 51 | default: |
| 52 | fmt.Println("Bad formatting function:", format) |
| 53 | os.Exit(1) |
| 54 | } |
| 55 | |
| 56 | if len(args) == 0 { |
| 57 | for i := 0; i < count; i++ { |
| 58 | args = append(args, ksuid.New().String()) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | var ids []ksuid.KSUID |
| 63 | for _, arg := range args { |
| 64 | id, err := ksuid.Parse(arg) |
| 65 | if err != nil { |
| 66 | fmt.Printf("Error when parsing %q: %s\n\n", arg, err) |
| 67 | flag.PrintDefaults() |
| 68 | os.Exit(1) |
| 69 | } |
| 70 | ids = append(ids, id) |
| 71 | } |
| 72 | |
| 73 | for _, id := range ids { |
| 74 | if verbose { |
| 75 | fmt.Printf("%s: ", id) |
| 76 | } |
| 77 | print(id) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | func printString(id ksuid.KSUID) { |
| 82 | fmt.Println(id.String()) |