Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
fix botway new command
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Sep 21, 2022
1 parent 9602312 commit 3ddfc0f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/app/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/exec"
"runtime"

"github.com/abdfnx/botway/internal/config"
"github.com/abdfnx/botway/internal/options"
"github.com/abdfnx/botway/internal/pipes/new"
"github.com/abdfnx/botway/tools"
Expand Down Expand Up @@ -38,11 +39,14 @@ func NewCMD() *cobra.Command {
if !newOpts.NoRepo {
new.CreateRepo(newOpts, opts.BotName)
}

if config.GetBotInfoFromArg(args[0], "bot.host_service") == "railway.app" {
cmd.PostRunE = Contextualize(handler.Init, handler.Panic)
}
} else {
cmd.Help()
}
},
PostRunE: Contextualize(handler.Init, handler.Panic),
PersistentPostRun: func(cmd *cobra.Command, args []string) {
if runtime.GOOS != "windows" {
fmt.Println(messageStyle.Render("> Installing some required packages"))
Expand All @@ -54,7 +58,7 @@ func NewCMD() *cobra.Command {
if err != nil {
panic("error: brew is not installed")
} else {
cmd = brewPath+" install opus libsodium"
cmd = brewPath + " install opus libsodium"
}
}

Expand Down
21 changes: 21 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package config

import (
"bytes"
"io/ioutil"
"path/filepath"

"github.com/abdfnx/botway/constants"
"github.com/spf13/viper"
"github.com/tidwall/gjson"
)

Expand All @@ -10,3 +15,19 @@ func Get(value string) string {

return c.String()
}

func GetBotInfoFromArg(botName, value string) string {
c := viper.New()

c.SetConfigType("yaml")

botConfig, err := ioutil.ReadFile(filepath.Join(botName, ".botway.yaml"))

if err != nil {
panic(err)
}

c.ReadConfig(bytes.NewBuffer(botConfig))

return c.GetString(value)
}

0 comments on commit 3ddfc0f

Please sign in to comment.