mirror of
https://github.com/apernet/hysteria.git
synced 2025-04-05 13:37:45 +03:00
Tweaks to the CLI to ensure consistent behavior with previous versions
This commit is contained in:
parent
3f5bd76480
commit
060948188e
1 changed files with 47 additions and 49 deletions
72
cmd/main.go
72
cmd/main.go
|
@ -22,47 +22,36 @@ var (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "hysteria",
|
Name: "Hysteria",
|
||||||
Usage: "A TCP/UDP relay & SOCKS5/HTTP proxy tool",
|
Usage: "a TCP/UDP relay & SOCKS5/HTTP proxy tool optimized for poor network environments",
|
||||||
Version: fmt.Sprintf("%s %s %s", appVersion, appDate, appCommit),
|
Version: fmt.Sprintf("%s %s %s", appVersion, appDate, appCommit),
|
||||||
Authors: []*cli.Author{{Name: "HyNetwork <https://github.com/HyNetwork>"}},
|
Authors: []*cli.Author{{Name: "HyNetwork <https://github.com/HyNetwork>"}},
|
||||||
EnableBashCompletion: true,
|
EnableBashCompletion: true,
|
||||||
Action: func(c *cli.Context) error {
|
Action: clientAction,
|
||||||
return cli.ShowAppHelp(c)
|
Flags: commonFlags(),
|
||||||
},
|
Before: initApp,
|
||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
{
|
{
|
||||||
Name: "server",
|
Name: "server",
|
||||||
Usage: "Run as server mode",
|
Usage: "Run as server mode",
|
||||||
Before: initApp,
|
Action: serverAction,
|
||||||
Flags: commonFlags(),
|
|
||||||
Action: func(c *cli.Context) error {
|
|
||||||
cbs, err := ioutil.ReadFile(c.String("config"))
|
|
||||||
if err != nil {
|
|
||||||
logrus.WithFields(logrus.Fields{
|
|
||||||
"file": c.String("config"),
|
|
||||||
"error": err,
|
|
||||||
}).Fatal("Failed to read configuration")
|
|
||||||
}
|
|
||||||
|
|
||||||
// server mode
|
|
||||||
sc, err := parseServerConfig(cbs)
|
|
||||||
if err != nil {
|
|
||||||
logrus.WithFields(logrus.Fields{
|
|
||||||
"file": c.String("config"),
|
|
||||||
"error": err,
|
|
||||||
}).Fatal("Failed to parse server configuration")
|
|
||||||
}
|
|
||||||
server(sc)
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "client",
|
Name: "client",
|
||||||
Usage: "Run as client mode",
|
Usage: "Run as client mode",
|
||||||
Before: initApp,
|
Action: clientAction,
|
||||||
Flags: commonFlags(),
|
},
|
||||||
Action: func(c *cli.Context) error {
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := app.Run(os.Args)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func clientAction(c *cli.Context) error {
|
||||||
cbs, err := ioutil.ReadFile(c.String("config"))
|
cbs, err := ioutil.ReadFile(c.String("config"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
|
@ -70,7 +59,6 @@ func main() {
|
||||||
"error": err,
|
"error": err,
|
||||||
}).Fatal("Failed to read configuration")
|
}).Fatal("Failed to read configuration")
|
||||||
}
|
}
|
||||||
|
|
||||||
// client mode
|
// client mode
|
||||||
cc, err := parseClientConfig(cbs)
|
cc, err := parseClientConfig(cbs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -81,16 +69,26 @@ func main() {
|
||||||
}
|
}
|
||||||
client(cc)
|
client(cc)
|
||||||
return nil
|
return nil
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := app.Run(os.Args)
|
func serverAction(c *cli.Context) error {
|
||||||
|
cbs, err := ioutil.ReadFile(c.String("config"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"file": c.String("config"),
|
||||||
|
"error": err,
|
||||||
|
}).Fatal("Failed to read configuration")
|
||||||
}
|
}
|
||||||
|
// server mode
|
||||||
|
sc, err := parseServerConfig(cbs)
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"file": c.String("config"),
|
||||||
|
"error": err,
|
||||||
|
}).Fatal("Failed to parse server configuration")
|
||||||
|
}
|
||||||
|
server(sc)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseServerConfig(cb []byte) (*serverConfig, error) {
|
func parseServerConfig(cb []byte) (*serverConfig, error) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue