Skip to content

Commit

Permalink
Added version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
swarman committed Aug 26, 2016
1 parent 0481a0e commit 631d186
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions .promu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repository:
build:
flags: -a -tags 'netgo static_build'
ldflags:
-X main.Version={{.Version}}
tarball:
files:
crossbuild:
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ crossbuild: prerequisites
$(PROMU) crossbuild
$(PROMU) crossbuild tarballs

.PHONY: release
release:
#requires GITHUB_TOKEN environment variable with valid token and an
#already created release on github
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1
0.0.2
22 changes: 16 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ import (
)

var (
configPath = flag.String("config", "config.yml", "Path to config YAML file.")
verbose = flag.Bool("verbose", false, "Log more information")
Version = "unknown"
)

var (
configPathFlag = flag.String("config", "config.yml", "Path to config YAML file.")
verboseFlag = flag.Bool("verbose", false, "Log more information")
versionFlag = flag.Bool("version", false, "Show version and exit")
)

type Config struct {
Expand All @@ -30,15 +35,20 @@ func main() {

flag.Parse()

configFile, err := os.Open(*configPath)
if *versionFlag {
fmt.Print(Version)
os.Exit(0)
}

configFile, err := os.Open(*configPathFlag)
if err != nil {
log.Fatalf("Failed to open config file at path %s due to error: %s", *configPath, err.Error())
log.Fatalf("Failed to open config file at path %s due to error: %s", *configPathFlag, err.Error())
}
defer configFile.Close()

configData, err := ioutil.ReadAll(configFile)
if err != nil {
log.Fatalf("Failed to read config file at path %s due to error: %s", *configPath, err.Error())
log.Fatalf("Failed to read config file at path %s due to error: %s", *configPathFlag, err.Error())
}

config := &Config{}
Expand Down Expand Up @@ -116,7 +126,7 @@ func (f *Aggregator) Aggregate(targets []string, output io.Writer) {
log.Printf("Result body close error: %s", err.Error())
}

if *verbose {
if *verboseFlag {
log.Printf("OK: %s was refreshed in %.3f seconds", result.URL, result.SecondsTaken)
}
}
Expand Down

0 comments on commit 631d186

Please sign in to comment.