Skip to content

Commit

Permalink
add -version / --version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Jan 19, 2025
1 parent 6cc5e28 commit 846ff16
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions main_gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ package main

import (
"flag"
"fmt"
"log/slog"
"os"

"github.com/ilius/ayandict/v2/pkg/appinfo"
"github.com/ilius/ayandict/v2/pkg/application"
"github.com/ilius/ayandict/v2/pkg/config"
"github.com/ilius/ayandict/v2/pkg/dictmgr"
Expand All @@ -33,6 +35,11 @@ func runServerOnly(createConfig bool) {
}

func main() {
versionFlag := flag.Bool(
"version",
false,
"Show version and exit",
)
noGuiFlag := flag.Bool(
"no-gui",
false,
Expand All @@ -45,6 +52,11 @@ func main() {
)
flag.Parse()

if *versionFlag {
fmt.Printf("%v %v\n", appinfo.APP_DESC, appinfo.VERSION)
os.Exit(0)
}

// slog uses stdout
noColor := os.Getenv("NO_COLOLR") != ""
logging.SetupLogger(noColor, logging.DefaultLevel)
Expand Down
12 changes: 12 additions & 0 deletions main_no_gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ package main

import (
"flag"
"fmt"
"log/slog"
"os"

"github.com/ilius/ayandict/v2/pkg/appinfo"
"github.com/ilius/ayandict/v2/pkg/config"
"github.com/ilius/ayandict/v2/pkg/dictmgr"
"github.com/ilius/ayandict/v2/pkg/logging"
Expand All @@ -16,13 +18,23 @@ import (
func main() {
// slog uses stdout

versionFlag := flag.Bool(
"version",
false,
"Show version and exit",
)
createConfigFlag := flag.Bool(
"create-config",
false,
"Create config file (with defaults) if it does not exist",
)
flag.Parse()

if *versionFlag {
fmt.Printf("%v %v (non-GUI build)\n", appinfo.APP_DESC, appinfo.VERSION)
os.Exit(0)
}

conf, err := config.Load()
if err != nil {
panic(err)
Expand Down

0 comments on commit 846ff16

Please sign in to comment.