]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Improve 命令行参数支持从环境变量获取
authorqydysky <qydysky@foxmail.com>
Sun, 20 Oct 2024 01:38:47 +0000 (09:38 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 20 Oct 2024 01:38:47 +0000 (09:38 +0800)
CV/Var.go
README.md

index d72d35beb8888c9dd87c5f6bee999d1fe74945cd..2528d3d2cdc6049734339bebacad9419cedea093 100644 (file)
--- a/CV/Var.go
+++ b/CV/Var.go
@@ -13,6 +13,7 @@ import (
        "net/url"
        "os"
        "runtime"
+       "strconv"
        "strings"
        "sync"
        "testing"
@@ -393,6 +394,18 @@ func (t *Common) Init() *Common {
                }
        }
 
+       // load from env
+       if tmp := os.Getenv("ckv"); *ckv == "" && tmp != "" {
+               fmt.Println("加载环境变量ckv:", tmp)
+               *ckv = tmp
+       }
+       if tmp := os.Getenv("r"); *roomIdP == 0 && tmp != "" {
+               fmt.Println("加载环境变量r:", tmp)
+               if r, e := strconv.Atoi(tmp); e == nil {
+                       *roomIdP = r
+               }
+       }
+
        t.Roomid = *roomIdP
 
        if e := t.loadConf(*ckv); e != nil {
index 038b595fbe5dcb3f37247c95f73ff2ab18e00541..2b329be3f649b8f234c3c89aabc0a8dd0265b252 100644 (file)
--- a/README.md
+++ b/README.md
@@ -956,6 +956,7 @@ go build .
 
 #### 注意事项
 * 其中[]内的内容为可选项
+* 当`-r`,`-ckv`为空时,将尝试从环境变量中获取,分别对应键值`r`,`ckv`(>v0.14.21)
 * 法1,2,3建议使用最新提交
 * 程序受主机时区配置影响,注意正确配置主机时区
 * 弹幕及礼物会记录于danmu.log中