2020-02-16 06:51:14 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-02-17 21:50:02 +01:00
|
|
|
"gitea.com/jolheiser/sip/modules/config"
|
2020-05-07 03:09:31 +02:00
|
|
|
|
2020-02-16 06:51:14 +01:00
|
|
|
"github.com/AlecAivazis/survey/v2"
|
|
|
|
"github.com/urfave/cli/v2"
|
2020-02-27 03:53:11 +01:00
|
|
|
"go.jolheiser.com/beaver"
|
2020-02-16 06:51:14 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var Config = cli.Command{
|
|
|
|
Name: "config",
|
|
|
|
Aliases: []string{"cfg"},
|
2020-02-17 22:07:00 +01:00
|
|
|
Usage: "Modify Sip config",
|
2020-02-16 06:51:14 +01:00
|
|
|
Action: doConfig,
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
{
|
2020-02-17 06:28:11 +01:00
|
|
|
Name: "origin",
|
|
|
|
Usage: "Specify default origin name",
|
|
|
|
Action: doConfigOrigin,
|
2020-02-16 06:51:14 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "upstream",
|
|
|
|
Usage: "Specify default upstream name",
|
|
|
|
Action: doConfigUpstream,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func doConfig(ctx *cli.Context) error {
|
2020-02-17 06:28:11 +01:00
|
|
|
if err := doConfigOrigin(ctx); err != nil {
|
2020-02-16 06:51:14 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return doConfigUpstream(ctx)
|
|
|
|
}
|
|
|
|
|
2020-02-17 06:28:11 +01:00
|
|
|
func doConfigOrigin(ctx *cli.Context) error {
|
2020-02-16 06:51:14 +01:00
|
|
|
question := &survey.Input{
|
2020-02-17 06:28:11 +01:00
|
|
|
Message: "Default origin name",
|
2020-02-16 06:51:14 +01:00
|
|
|
Default: "origin",
|
|
|
|
}
|
|
|
|
var answer string
|
|
|
|
if err := survey.AskOne(question, &answer); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-16 23:31:01 +01:00
|
|
|
config.Origin = answer
|
2020-02-16 06:51:14 +01:00
|
|
|
if err := config.Save(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-16 23:31:01 +01:00
|
|
|
beaver.Info("Default origin saved!")
|
2020-02-16 06:51:14 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func doConfigUpstream(ctx *cli.Context) error {
|
|
|
|
question := &survey.Input{
|
|
|
|
Message: "Default upstream name",
|
|
|
|
Default: "upstream",
|
|
|
|
}
|
|
|
|
var answer string
|
|
|
|
if err := survey.AskOne(question, &answer); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Upstream = answer
|
|
|
|
if err := config.Save(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
beaver.Info("Default upstream saved!")
|
|
|
|
return nil
|
|
|
|
}
|