Skip to content

Commit

Permalink
Add version information and flag to show it
Browse files Browse the repository at this point in the history
  • Loading branch information
basbossink committed Nov 19, 2021
1 parent c715b3a commit 6e4e70f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version := `git describe --tags --exact-match`
hash := `git rev-parse HEAD`
build:
go build -ldflags="-X main.Version={{version}} -X main.CommitHash={{hash}}"
23 changes: 22 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/binary"
"encoding/gob"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -33,6 +34,8 @@ const (
var (
ErrInsufficientSize = errors.New("buffer is to small")
ErrFileCorrupt = errors.New("corrupt file")
Version string
CommitHash string
)

type entry struct {
Expand Down Expand Up @@ -256,8 +259,26 @@ func convertArgsToEntry(args []string) entry {
entry := entry{Note: note, Tags: tags, CreatedAt: time.Now()}
return entry
}

func usage() {
fmt.Fprintf(
flag.CommandLine.Output(),
"Usage of %s: [option] [sentence describing activity to note, words beginning with an @ are taken to be tags]\n",
os.Args[0])
fmt.Fprintln(
flag.CommandLine.Output(),
"If no arguments are given, a table with the latest notes is shown.")
flag.PrintDefaults()
}
func main() {
showVersion := false
flag.Usage = usage
flag.BoolVar(&showVersion, "version", false, "show version and exit")
flag.BoolVar(&showVersion, "v", false, "show version and exit")
flag.Parse()
if showVersion {
fmt.Println(os.Args[0], " version: ", Version, CommitHash)
os.Exit(0)
}
dataDir, err := ensureDataDir()
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 6e4e70f

Please sign in to comment.