2022-09-04 14:53:21 +00:00
|
|
|
package subcommands
|
2022-04-03 20:12:21 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"flag"
|
|
|
|
|
2023-01-23 12:40:12 +00:00
|
|
|
"github.com/bedrock-tool/bedrocktool/locale"
|
2022-09-04 14:53:21 +00:00
|
|
|
"github.com/bedrock-tool/bedrocktool/utils"
|
2022-04-03 20:12:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2022-09-04 14:26:32 +00:00
|
|
|
utils.RegisterCommand(&CaptureCMD{})
|
2022-04-03 20:12:21 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 20:55:52 +00:00
|
|
|
type CaptureCMD struct {
|
2023-03-06 01:03:31 +00:00
|
|
|
ServerAddress string
|
2022-08-14 20:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*CaptureCMD) Name() string { return "capture" }
|
2023-01-23 12:40:12 +00:00
|
|
|
func (*CaptureCMD) Synopsis() string { return locale.Loc("capture_synopsis", nil) }
|
2023-01-29 21:20:13 +00:00
|
|
|
func (c *CaptureCMD) SetFlags(f *flag.FlagSet) {
|
2023-03-06 01:03:31 +00:00
|
|
|
f.StringVar(&c.ServerAddress, "address", "", "remote server address")
|
2023-03-05 21:50:58 +00:00
|
|
|
}
|
|
|
|
|
2023-03-06 20:49:30 +00:00
|
|
|
func (c *CaptureCMD) 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-04-03 20:12:21 +00:00
|
|
|
if err != nil {
|
2023-03-06 20:49:30 +00:00
|
|
|
return err
|
2022-04-03 20:12:21 +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 {
|
2023-04-01 22:22:50 +00:00
|
|
|
return err
|
2023-02-12 21:22:44 +00:00
|
|
|
}
|
2023-04-17 19:48:12 +00:00
|
|
|
proxy.AlwaysGetPacks = true
|
2023-04-20 22:55:52 +00:00
|
|
|
utils.Options.Capture = true
|
2023-04-02 14:49:24 +00:00
|
|
|
return proxy.Run(ctx, address, hostname)
|
2022-04-03 20:12:21 +00:00
|
|
|
}
|