-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmdline.go
More file actions
62 lines (54 loc) · 1.63 KB
/
cmdline.go
File metadata and controls
62 lines (54 loc) · 1.63 KB
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
package main
import (
"flag"
"fmt"
"log/slog"
"os"
)
// Process is the function that handles the command line flags. The flags
// processed are: -l, log level and -f, config file location.
//
// log level may be set to err, warn, info or debug.
//
// the file is set to a string which must be the path to a valid config file
func ProcessFlags() (*ClArgs, error) {
cl := ClArgs{}
var ver bool
var json bool
var debugPost bool
logLevelPtr := flag.String("l", "info", "used to set the logging level, may be err, warn, info or debug")
configFilePathPtr := flag.String("f", "", "specifies the location of the configuration file")
flag.BoolVar(&ver, "v", false, "prints the version and quits")
logPathPtr := flag.String("o", "", "specifies the path of the log file, default logging happens in the console")
flag.BoolVar(&json, "j", false, "sets json log format")
flag.BoolVar(&debugPost, "p", false, "if enabled, debug logging will include all scanned posts - very noisy!")
flag.Parse()
cl.JsonLog = json
cl.ConfigFilePath = *configFilePathPtr
cl.LogPath = *logPathPtr
switch *logLevelPtr {
case "err":
cl.LogLevel = slog.LevelError
LogLevel = slog.LevelError
case "warn":
cl.LogLevel = slog.LevelWarn
LogLevel = slog.LevelWarn
case "info":
cl.LogLevel = slog.LevelInfo
LogLevel = slog.LevelInfo
case "debug":
cl.LogLevel = slog.LevelDebug
LogLevel = slog.LevelDebug
default:
return nil, fmt.Errorf("log level '%s' not supported", *logLevelPtr)
}
if debugPost {
DebugPosts = true
}
if ver {
fmt.Printf("Version:\t%s\n", ReleaseVersion)
fmt.Printf("BuildTime:\t%s\n", BuildTime)
os.Exit(0)
}
return &cl, nil
}