-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (35 loc) · 857 Bytes
/
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
package main
import (
"flag"
"fmt"
"os"
"runtime"
"strings"
)
const ver string = "1.0.0"
func main() {
help := flag.Bool("help", false, "display this help and exit")
version := flag.Bool("version", false, "output version information and exit")
flag.Parse()
if *help {
fmt.Fprintln(os.Stderr, "go-yes repeatedly outputs a line with specified string, or 'y'.")
fmt.Fprintln(os.Stderr)
fmt.Fprintf(os.Stderr, "Usage: %s [OPTIONS]\n", os.Args[0])
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, "Options:")
flag.PrintDefaults()
os.Exit(0)
}
if *version {
fmt.Fprintf(os.Stderr, "go-yes version %s\n", ver)
fmt.Fprintf(os.Stderr, "Go version %s\n", runtime.Version())
os.Exit(0)
}
for {
if len(os.Args) >= 2 {
fmt.Fprintln(os.Stdout, strings.Join(os.Args[1:], " "))
} else {
fmt.Fprintln(os.Stdout, "y")
}
}
}