Skip to content

Commit 0738b5a

Browse files
author
Łukasz Kostka
committed
Version printing in cmd args
1 parent 738e3d4 commit 0738b5a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

main.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"bytes"
55
"flag"
6+
"fmt"
67
"io"
78
"io/ioutil"
89
"log/syslog"
@@ -17,6 +18,8 @@ import (
1718
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
1819
)
1920

21+
var version string
22+
2023
const defaultConfigFile = "/etc/awslogs.conf"
2124

2225
type writerHook struct {
@@ -60,14 +63,23 @@ func pickHook(out logoutput) log.Hook {
6063
}
6164
}
6265

63-
func main() {
66+
func init() {
6467
debug()
65-
log.SetFormatter(&programFormat{})
66-
log.SetOutput(os.Stderr)
67-
log.SetLevel(log.ErrorLevel)
68+
}
69+
70+
func main() {
6871
var cfgfile string
72+
var print_version bool
6973
flag.StringVar(&cfgfile, "c", defaultConfigFile, "Config file location.")
74+
flag.BoolVar(&print_version, "v", false, "Print version and exit.")
7075
flag.Parse()
76+
if print_version {
77+
fmt.Println(version)
78+
os.Exit(0)
79+
}
80+
log.SetFormatter(&programFormat{})
81+
log.SetOutput(os.Stderr)
82+
log.SetLevel(log.ErrorLevel)
7183
config := getConfig(cfgfile)
7284
settings := getMainConfig(config)
7385
flows := getFlows(config)

0 commit comments

Comments
 (0)