mirror of
https://github.com/CosmicStar98/bedrocktool.git
synced 2024-06-02 02:35:15 +00:00
add press enter to exit
This commit is contained in:
parent
0911a80492
commit
833427895a
|
@ -20,12 +20,11 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func exit() {
|
func cleanup() {
|
||||||
logrus.Info("\nExiting\n")
|
logrus.Info("\nCleaning up\n")
|
||||||
for i := len(utils.G_exit) - 1; i >= 0; i-- { // go through cleanup functions reversed
|
for i := len(utils.G_cleanup_funcs) - 1; i >= 0; i-- { // go through cleanup functions reversed
|
||||||
utils.G_exit[i]()
|
utils.G_cleanup_funcs[i]()
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -43,6 +42,10 @@ func main() {
|
||||||
println("https://github.com/bedrock-tool/bedrocktool/issues")
|
println("https://github.com/bedrock-tool/bedrocktool/issues")
|
||||||
println("And attach the error info, describe what you did to get this error.")
|
println("And attach the error info, describe what you did to get this error.")
|
||||||
println("Thanks!\n")
|
println("Thanks!\n")
|
||||||
|
if utils.G_interactive {
|
||||||
|
input := bufio.NewScanner(os.Stdin)
|
||||||
|
input.Scan()
|
||||||
|
}
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -91,6 +94,7 @@ func main() {
|
||||||
r, _ := regexp.Compile(`[\n\r]`)
|
r, _ := regexp.Compile(`[\n\r]`)
|
||||||
target = string(r.ReplaceAll([]byte(target), []byte("")))
|
target = string(r.ReplaceAll([]byte(target), []byte("")))
|
||||||
os.Args = append(os.Args, target)
|
os.Args = append(os.Args, target)
|
||||||
|
utils.G_interactive = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,11 +111,17 @@ func main() {
|
||||||
go func() {
|
go func() {
|
||||||
<-sigs
|
<-sigs
|
||||||
cancel()
|
cancel()
|
||||||
exit()
|
cleanup()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ret := subcommands.Execute(ctx)
|
ret := subcommands.Execute(ctx)
|
||||||
exit()
|
cleanup()
|
||||||
|
|
||||||
|
if utils.G_interactive {
|
||||||
|
logrus.Info("Press Enter to exit.")
|
||||||
|
input := bufio.NewScanner(os.Stdin)
|
||||||
|
input.Scan()
|
||||||
|
}
|
||||||
os.Exit(int(ret))
|
os.Exit(int(ret))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -478,7 +478,7 @@ func (w *WorldState) OnConnect(proxy *utils.ProxyContext) {
|
||||||
|
|
||||||
w.proxy.SendMessage("use /setname <worldname>\nto set the world name")
|
w.proxy.SendMessage("use /setname <worldname>\nto set the world name")
|
||||||
|
|
||||||
utils.G_exit = append(utils.G_exit, func() {
|
utils.G_cleanup_funcs = append(utils.G_cleanup_funcs, func() {
|
||||||
w.SaveAndReset()
|
w.SaveAndReset()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,8 @@ const SERVER_ADDRESS_HELP = `accepted server address formats:
|
||||||
var (
|
var (
|
||||||
G_debug bool
|
G_debug bool
|
||||||
G_preload_packs bool
|
G_preload_packs bool
|
||||||
G_exit []func() = []func(){}
|
G_interactive bool
|
||||||
|
G_cleanup_funcs []func() = []func(){}
|
||||||
)
|
)
|
||||||
|
|
||||||
var A string
|
var A string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user