bedrocktool/subcommands/chat_log.go

41 lines
955 B
Go
Raw Permalink Normal View History

2022-09-09 18:11:45 +00:00
package subcommands
import (
"context"
"flag"
2023-04-04 00:47:25 +00:00
"github.com/bedrock-tool/bedrocktool/handlers"
"github.com/bedrock-tool/bedrocktool/locale"
2022-09-09 18:11:45 +00:00
"github.com/bedrock-tool/bedrocktool/utils"
)
type ChatLogCMD struct {
2023-03-06 01:03:31 +00:00
ServerAddress string
Verbose bool
2022-09-09 18:11:45 +00:00
}
func (*ChatLogCMD) Name() string { return "chat-log" }
func (*ChatLogCMD) Synopsis() string { return locale.Loc("chat_log_synopsis", nil) }
2022-09-09 18:11:45 +00:00
func (c *ChatLogCMD) SetFlags(f *flag.FlagSet) {
2023-03-06 01:03:31 +00:00
f.StringVar(&c.ServerAddress, "address", "", "remote server address")
f.BoolVar(&c.Verbose, "v", false, "verbose")
2022-09-09 18:11:45 +00:00
}
func (c *ChatLogCMD) Execute(ctx context.Context, ui utils.UI) error {
2023-03-06 01:03:31 +00:00
address, hostname, err := utils.ServerInput(ctx, c.ServerAddress)
2022-09-09 18:11:45 +00:00
if err != nil {
return err
2022-09-09 18:11:45 +00:00
}
2023-03-06 01:03:31 +00:00
proxy, err := utils.NewProxy()
2023-02-12 21:22:44 +00:00
if err != nil {
return err
2023-02-12 21:22:44 +00:00
}
2023-04-02 14:49:24 +00:00
proxy.AddHandler(handlers.NewChatLogger())
return proxy.Run(ctx, address, hostname)
2022-09-09 18:11:45 +00:00
}
func init() {
utils.RegisterCommand(&ChatLogCMD{})
}