diff --git a/cmd/app/new.go b/cmd/app/new.go index 7fed38a2..c3778485 100755 --- a/cmd/app/new.go +++ b/cmd/app/new.go @@ -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" @@ -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")) @@ -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" } } diff --git a/internal/config/config.go b/internal/config/config.go index 04015284..59ad1d52 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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" ) @@ -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) +}