Skip to content

Commit

Permalink
feat(cmd): add version commmand
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMarble committed Apr 7, 2022
1 parent 49cf5ab commit 7b35051
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cmd/termsvg/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"

"github.com/alecthomas/kong"
Expand All @@ -11,10 +12,27 @@ import (
"github.com/rs/zerolog/log"
)

var (
// Populated by goreleaser during build
version = "master"
commit = "?"
date = ""
)

type Context struct {
Debug bool
}

type VersionFlag string

func (v VersionFlag) Decode(ctx *kong.DecodeContext) error { return nil }
func (v VersionFlag) IsBool() bool { return true }
func (v VersionFlag) BeforeApply(app *kong.Kong) error {
fmt.Printf("termsvg has version %s built from %s on %s\n", version, commit, date)
app.Exit(0)
return nil
}

func init() {
zerolog.SetGlobalLevel(zerolog.InfoLevel)

Expand All @@ -23,7 +41,8 @@ func init() {

func main() {
var cli struct {
Debug bool `help:"Enable debug mode."`
Debug bool `help:"Enable debug mode."`
Version VersionFlag `name:"version" help:"Print version information and quit"`

Play play.Cmd `cmd:"" help:"Play a recording."`
Rec rec.Cmd `cmd:"" help:"Record a terminal sesion."`
Expand Down

0 comments on commit 7b35051

Please sign in to comment.