-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (54 loc) · 1.15 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"flag"
"fmt"
"log"
"os"
"strconv"
)
const (
defX = 2
defY = 2
)
var (
startWith = flag.Int("start", 1, "Start with this number")
sep = flag.String("sep", "-", "Separator between prefix and number")
)
func init() { flag.Usage = usage }
func main() {
flag.Parse()
if flag.NArg() == 0 {
flag.Usage()
os.Exit(1)
}
prefix := flag.Arg(0)
x, y := defX, defY
if flag.NArg() > 1 {
x = a2iOrDie(flag.Arg(1))
}
if flag.NArg() > 2 {
y = a2iOrDie(flag.Arg(2))
}
n := *startWith
for col := 0; col < x; col++ {
for row := 0; row < y; row++ {
fmt.Printf(":%s%s%d:", prefix, *sep, n)
n++
}
fmt.Println()
}
}
func a2iOrDie(s string) int {
i, err := strconv.Atoi(s)
if err != nil {
log.Fatal(err)
}
return i
}
func usage() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [flags] <prefix> [x] [y]\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), "Where x is the number of emojis in the line (default: %d)\n", defX)
fmt.Fprintf(flag.CommandLine.Output(), " y is the number of lines (default: %d)\n\n", defY)
fmt.Fprintf(flag.CommandLine.Output(), "Flags:\n")
flag.PrintDefaults()
}