mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
feat: set work directory
This commit is contained in:
parent
0138a6c467
commit
1f45c596b2
18
main.go
18
main.go
@ -10,6 +10,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -42,6 +43,7 @@ var (
|
|||||||
c string
|
c string
|
||||||
d bool
|
d bool
|
||||||
h bool
|
h bool
|
||||||
|
wd string // reset work dir
|
||||||
|
|
||||||
// PasswordHash 存储QQ密码哈希供登录使用
|
// PasswordHash 存储QQ密码哈希供登录使用
|
||||||
PasswordHash [16]byte
|
PasswordHash [16]byte
|
||||||
@ -65,6 +67,7 @@ func init() {
|
|||||||
flag.BoolVar(&d, "d", false, "running as a daemon")
|
flag.BoolVar(&d, "d", false, "running as a daemon")
|
||||||
flag.BoolVar(&debug, "D", false, "debug mode")
|
flag.BoolVar(&debug, "D", false, "debug mode")
|
||||||
flag.BoolVar(&h, "h", false, "this help")
|
flag.BoolVar(&h, "h", false, "this help")
|
||||||
|
flag.StringVar(&wd, "w", "", "cover the working directory")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// 通过-c 参数替换 配置文件路径
|
// 通过-c 参数替换 配置文件路径
|
||||||
@ -119,6 +122,9 @@ func main() {
|
|||||||
if d {
|
if d {
|
||||||
server.Daemon()
|
server.Daemon()
|
||||||
}
|
}
|
||||||
|
if wd != "" {
|
||||||
|
resetWorkDir()
|
||||||
|
}
|
||||||
var byteKey []byte
|
var byteKey []byte
|
||||||
arg := os.Args
|
arg := os.Args
|
||||||
if len(arg) > 1 {
|
if len(arg) > 1 {
|
||||||
@ -608,3 +614,15 @@ Options:
|
|||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resetWorkDir() {
|
||||||
|
proc := exec.Command(os.Args[0], flag.Args()...)
|
||||||
|
proc.Stdin = os.Stdin
|
||||||
|
proc.Stdout = os.Stdout
|
||||||
|
proc.Dir = wd
|
||||||
|
err := proc.Run()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user