1
0
mirror of https://github.com/taigrr/shorturl synced 2025-01-18 04:03:16 -08:00

Add version information and -v flag

This commit is contained in:
James Mills 2017-08-31 23:36:04 -07:00
parent 2f94823208
commit 2dad0e7011
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6
2 changed files with 25 additions and 0 deletions

View File

@ -1,7 +1,9 @@
package main
import (
"fmt"
"log"
"os"
"github.com/boltdb/bolt"
"github.com/namsral/flag"
@ -14,18 +16,25 @@ var (
func main() {
var (
version bool
config string
dbpath string
baseurl string
bind string
)
flag.BoolVar(&version, "v", false, "display version information")
flag.StringVar(&config, "config", "", "config file")
flag.StringVar(&dbpath, "dbpath", "urls.db", "Database path")
flag.StringVar(&baseurl, "baseurl", "", "Base URL for display purposes")
flag.StringVar(&bind, "bind", "0.0.0.0:8000", "[int]:<port> to bind to")
flag.Parse()
if version {
fmt.Printf("shorturl v%s", FullVersion())
os.Exit(0)
}
var err error
db, err = bolt.Open(dbpath, 0600, nil)
if err != nil {

16
version.go Normal file
View File

@ -0,0 +1,16 @@
package main
var (
// Version release version
Version = "0.0.1"
// Build will be overwritten automatically by the build system
Build = "-dev"
// GitCommit will be overwritten automatically by the build system
GitCommit = "HEAD"
)
func FullVersion() string {
return Version + Build + " (" + GitCommit + ")"
}