-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cli.go
50 lines (39 loc) · 1.09 KB
/
Cli.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
package main
import (
"flag"
"log/slog"
"os"
)
var version string
func printVersion() {
if version == "" {
version = "development"
}
println("amock version " + version)
}
var DebugValue = false
var versionFlag = flag.Bool("version", false, "Print the current version and exit")
var helpFlag = flag.Bool("help", false, "Print help message and exit")
var debugFlag = flag.Bool("debug", false, "Enable debug logging")
func parseFlags() {
flag.BoolVar(versionFlag, "v", false, "Print the current version and exit")
flag.BoolVar(debugFlag, "d", false, "Enable debug logging")
flag.BoolVar(helpFlag, "h", false, "Print help message and exit")
DebugValue = *debugFlag
flag.Parse()
if *versionFlag {
printVersion()
os.Exit(0)
}
if *helpFlag || len(flag.Args()) >= 0 && flag.Arg(0) == "help" {
println("Usage:\n\tamock [host:port] [flags]")
println("\n[host:port] - (optional) The host and port to bind the server to")
println("\nFlags: (optional)")
flag.PrintDefaults()
os.Exit(0)
}
if DebugValue {
LogLevel.Set(slog.LevelDebug)
slog.SetLogLoggerLevel(LogLevel.Level())
}
}