mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
988 B
49 lines
988 B
package command
|
|
|
|
//go:generate errorgen
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
"v2ray.com/core/common"
|
|
"v2ray.com/core/infra/conf/serial"
|
|
"v2ray.com/core/infra/control"
|
|
)
|
|
|
|
type ConfigCommand struct{}
|
|
|
|
func (c *ConfigCommand) Name() string {
|
|
return "config"
|
|
}
|
|
|
|
func (c *ConfigCommand) Description() control.Description {
|
|
return control.Description{
|
|
Short: "Convert config among different formats.",
|
|
Usage: []string{
|
|
"v2ctl config",
|
|
},
|
|
}
|
|
}
|
|
|
|
func (c *ConfigCommand) Execute(args []string) error {
|
|
pbConfig, err := serial.LoadJSONConfig(os.Stdin)
|
|
if err != nil {
|
|
return newError("failed to parse json config").Base(err)
|
|
}
|
|
|
|
bytesConfig, err := proto.Marshal(pbConfig)
|
|
if err != nil {
|
|
return newError("failed to marshal proto config").Base(err)
|
|
}
|
|
|
|
if _, err := os.Stdout.Write(bytesConfig); err != nil {
|
|
return newError("failed to write proto config").Base(err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
common.Must(control.RegisterCommand(&ConfigCommand{}))
|
|
}
|