Skip to content

Commit

Permalink
add --create-config flag for nogui mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Oct 5, 2024
1 parent 37f6717 commit b080161
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
15 changes: 13 additions & 2 deletions main_gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ import (
"github.com/ilius/ayandict/v2/pkg/server"
)

func runServerOnly() {
func runServerOnly(createConfig bool) {
conf, err := config.Load()
if err != nil {
panic(err)
}
if createConfig {
err := config.EnsureExists(conf)
if err != nil {
log.Printf("Failed creating config file: %v", err)
}
}
dictmgr.InitDicts(conf)
server.StartServer(conf.LocalServerPorts[0])
}
Expand All @@ -28,12 +34,17 @@ func main() {
false,
"Do not launch GUI",
)
createConfigFlag := flag.Bool(
"create-config",
false,
"With --no-gui: create config file (with defaults) if it does not exist",
)
flag.Parse()

log.SetOutput(os.Stdout)

if *noGuiFlag {
runServerOnly()
runServerOnly(*createConfigFlag)
return
}

Expand Down
17 changes: 17 additions & 0 deletions main_no_gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package main

import (
"flag"
"log"
"os"

Expand All @@ -13,10 +14,26 @@ import (

func main() {
log.SetOutput(os.Stdout)

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

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

if *createConfigFlag {
err := config.EnsureExists(conf)
if err != nil {
log.Printf("Failed creating config file: %v", err)
}
}

dictmgr.InitDicts(conf)
server.StartServer(conf.LocalServerPorts[0])
}
2 changes: 0 additions & 2 deletions pkg/config/config_save.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !nogui

package config

import (
Expand Down

0 comments on commit b080161

Please sign in to comment.