Add -version flag

This commit is contained in:
Trevor Slocum 2019-11-14 21:11:18 -08:00
parent 82c7976c5a
commit eee628190b
6 changed files with 33 additions and 9 deletions

View File

@ -2,6 +2,7 @@ package main
import (
"flag"
"fmt"
"log"
"os"
@ -30,6 +31,11 @@ func init() {
func main() {
flag.Parse()
if config.PrintVersion {
fmt.Printf(gmenu.VersionInfo, "gmenu", gmenu.Version)
return
}
tty := isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())
if !tty {
log.Fatal("failed to start gmenu: non-interactive terminals are not supported")

View File

@ -2,6 +2,7 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"path"
@ -49,6 +50,11 @@ func init() {
func load() {
flag.Parse()
if config.PrintVersion {
fmt.Printf(gmenu.VersionInfo, "gtkmenu", gmenu.Version)
return
}
homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)

5
go.mod
View File

@ -3,14 +3,15 @@ module git.sr.ht/~tslocum/gmenu
go 1.12
require (
git.sr.ht/~tslocum/desktop v0.1.1
git.sr.ht/~tslocum/desktop v0.1.2
github.com/gdamore/tcell v1.3.0
github.com/gotk3/gotk3 v0.0.0-20191027191019-60cba67d4ea4
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/lithammer/fuzzysearch v1.0.2
github.com/lucasb-eyer/go-colorful v1.0.3 // indirect
github.com/mattn/go-isatty v0.0.10
github.com/mattn/go-runewidth v0.0.6 // indirect
github.com/pkg/errors v0.8.1
github.com/rivo/tview v0.0.0-20191018125527-685bf6da76c2
golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd // indirect
golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056 // indirect
)

10
go.sum
View File

@ -1,5 +1,5 @@
git.sr.ht/~tslocum/desktop v0.1.1 h1:hS1DgT1Ur0DR42Z4vr+Zsasjjd8M9PVwIEmeAd1xLS4=
git.sr.ht/~tslocum/desktop v0.1.1/go.mod h1:cUn0Q8ALjkAq40qSei795yN3CfO5pkeYKo2gmzaZ2SI=
git.sr.ht/~tslocum/desktop v0.1.2 h1:S0u4Jb2yehJjrnrlnu7w7haVOc/K9oOJRR1mEi2EWcE=
git.sr.ht/~tslocum/desktop v0.1.2/go.mod h1:cUn0Q8ALjkAq40qSei795yN3CfO5pkeYKo2gmzaZ2SI=
github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFDnH08=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
@ -14,6 +14,8 @@ github.com/lithammer/fuzzysearch v1.0.2 h1:AjCE2iwc5y+8K+h2nXVc0Pmrpjvu+JVqMgiZ0
github.com/lithammer/fuzzysearch v1.0.2/go.mod h1:bvAJyokfCQ7Vknrd4Kgc+izmMrPj5CiBAu2t6rK1Kak=
github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
@ -29,8 +31,8 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191018095205-727590c5006e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd h1:3x5uuvBgE6oaXJjCOvpCC1IpgJogqQ+PqGGU3ZxAgII=
golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056 h1:dHtDnRWQtSx0Hjq9kvKFpBh9uPPKfQN70NZZmvssGwk=
golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=

View File

@ -1,6 +1,8 @@
package gmenu
type Config struct {
PrintVersion bool
DataDirs string
HideGenericNames bool
@ -26,4 +28,10 @@ func (c *Config) BrowserCommand() string {
return c.browserCommand
}
var Version string
const VersionInfo = `%s - Desktop application launcher - v%s
https://git.sr.ht/~tslocum/gmenu
The MIT License (MIT)
Copyright (c) 2019 Trevor Slocum <trevor@rocketnine.space>
`
var Version = "0.0.0"

View File

@ -20,7 +20,7 @@ var (
inputBuffer = make(chan string, 3)
input string
inputLower string
inputLower string
inputFlushed = make(chan bool)
)
@ -35,6 +35,7 @@ type InputUpdateHandler func(input string)
func SharedInit(c *Config) {
log.SetFlags(0)
flag.BoolVar(&c.PrintVersion, "version", false, "print version information and exit")
flag.StringVar(&c.DataDirs, "data-dirs", "", "application data directories (default: $XDG_DATA_DIRS)")
flag.BoolVar(&c.HideGenericNames, "no-generic", false, "hide application generic names")
flag.BoolVar(&c.HideAppDetails, "no-details", false, "hide application details")
@ -58,7 +59,7 @@ inputLoop:
input = in
inputLower = strings.ToLower(in)
u(input)
}
}