Skip to content

Commit

Permalink
feat(config): add cli config
Browse files Browse the repository at this point in the history
  • Loading branch information
indes committed Jun 27, 2019
1 parent 11f7f5d commit 853a21e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -250,4 +250,5 @@ __pycache__/*

config.yml

*.db
*.db
.dockerfile
23 changes: 19 additions & 4 deletions config/autoload.go
@@ -1,6 +1,7 @@
package config

import (
"flag"
"fmt"
"github.com/spf13/viper"
"strconv"
Expand All @@ -26,6 +27,12 @@ type MysqlConfig struct {
}

func init() {
telegramTokenCli := flag.String("k", "", "Telegram Bot Token")
telegraphTokenCli := flag.String("tk", "", "Telegraph API Token")
socks5Cli := flag.String("s", "", "Socks5 Proxy")
intervalCli := flag.Int("i", 0, "Update Interval")
flag.Parse()

projectName := "flowerss-bot"

viper.SetConfigName("config") // name of config file (without extension)
Expand All @@ -38,18 +45,26 @@ func init() {
panic(fmt.Errorf("Fatal error config file: %s", err))
}

BotToken = viper.GetString("bot_token")
Socks5 = viper.GetString("socks5")
if *telegramTokenCli == "" {
BotToken = viper.GetString("bot_token")

}

if *socks5Cli == "" {
Socks5 = viper.GetString("socks5")
}

if viper.IsSet("telegraph_token") {
if *telegraphTokenCli == "" && viper.IsSet("telegraph_token") {
EnableTelegraph = true
TelegraphToken = viper.GetString("telegraph_token")
} else {
EnableTelegraph = false
}

if viper.IsSet("update_interval") {
if *intervalCli == 0 && viper.IsSet("update_interval") {
UpdateInterval = viper.GetInt("update_interval")
} else {
UpdateInterval = 10
}

if viper.IsSet("mysql.host") {
Expand Down
1 change: 1 addition & 0 deletions main.go
Expand Up @@ -6,6 +6,7 @@ import (
)

func main() {

go task.Update()
bot.Start()
}

0 comments on commit 853a21e

Please sign in to comment.