mirror of
https://gitea.com/jolheiser/sip
synced 2024-11-23 04:12:00 +01:00
58fe648da6
Signed-off-by: jolheiser <john.olheiser@gmail.com>
73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"gitea.com/jolheiser/beaver"
|
|
"gitea.com/jolheiser/tea/modules/config"
|
|
"github.com/AlecAivazis/survey/v2"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var Config = cli.Command{
|
|
Name: "config",
|
|
Aliases: []string{"cfg"},
|
|
Usage: "Modify Tea config",
|
|
Action: doConfig,
|
|
Subcommands: []*cli.Command{
|
|
{
|
|
Name: "remote",
|
|
Usage: "Specify default remote name",
|
|
Action: doConfigRemote,
|
|
},
|
|
{
|
|
Name: "upstream",
|
|
Usage: "Specify default upstream name",
|
|
Action: doConfigUpstream,
|
|
},
|
|
},
|
|
}
|
|
|
|
func doConfig(ctx *cli.Context) error {
|
|
if err := doConfigRemote(ctx); err != nil {
|
|
return err
|
|
}
|
|
return doConfigUpstream(ctx)
|
|
}
|
|
|
|
func doConfigRemote(ctx *cli.Context) error {
|
|
question := &survey.Input{
|
|
Message: "Default remote name",
|
|
Default: "origin",
|
|
}
|
|
var answer string
|
|
if err := survey.AskOne(question, &answer); err != nil {
|
|
return err
|
|
}
|
|
|
|
config.Remote = answer
|
|
if err := config.Save(); err != nil {
|
|
return err
|
|
}
|
|
|
|
beaver.Info("Default remote saved!")
|
|
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
|
|
}
|