package cmd import ( "gitea.com/jolheiser/sip/config" "gitea.com/jolheiser/sip/prompt" "github.com/urfave/cli/v2" "go.jolheiser.com/beaver" ) var ( originFlag = &cli.StringFlag{ Name: "origin", Usage: "Default origin name", Value: "origin", } upstreamFlag = &cli.StringFlag{ Name: "upstream", Usage: "Default upstream name", Value: "upstream", } ) var Config = cli.Command{ Name: "config", Aliases: []string{"cfg"}, Usage: "Modify Sip config", Action: doConfig, Flags: []cli.Flag{ originFlag, upstreamFlag, }, Subcommands: []*cli.Command{ { Name: "origin", Usage: "Specify default origin name", Flags: []cli.Flag{ originFlag, }, Action: doConfigOrigin, }, { Name: "upstream", Usage: "Specify default upstream name", Flags: []cli.Flag{ upstreamFlag, }, Action: doConfigUpstream, }, }, } func doConfig(ctx *cli.Context) error { if err := doConfigOrigin(ctx); err != nil { return err } return doConfigUpstream(ctx) } func doConfigOrigin(ctx *cli.Context) error { origin, err := prompt.Input(ctx, originFlag, ctx.String("origin"), true) if err != nil { return err } config.Origin = origin if err := config.Save(); err != nil { return err } beaver.Info("Default origin saved!") return nil } func doConfigUpstream(ctx *cli.Context) error { upstream, err := prompt.Input(ctx, upstreamFlag, ctx.String("upstream"), true) if err != nil { return err } config.Upstream = upstream if err := config.Save(); err != nil { return err } beaver.Info("Default upstream saved!") return nil }