You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
synctv/cmd/setting/set.go

44 lines
979 B
Go

package setting
import (
"errors"
"fmt"
"github.com/spf13/cobra"
"github.com/synctv-org/synctv/internal/bootstrap"
"github.com/synctv-org/synctv/internal/settings"
)
var SetCmd = &cobra.Command{
Use: "set",
Short: "set setting",
Long: `set setting`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return bootstrap.New(bootstrap.WithContext(cmd.Context())).Add(
bootstrap.InitDiscardLog,
bootstrap.InitConfig,
bootstrap.InitDatabase,
bootstrap.InitSetting,
).Run()
},
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 2 {
return errors.New("args length must be 2")
}
s, ok := settings.Settings[args[0]]
if !ok {
return errors.New("setting not found")
}
err := s.SetString(args[1])
if err != nil {
fmt.Printf("set setting %s error: %v\n", args[0], err)
}
fmt.Printf("set setting success:\n%s: %v\n", args[0], s.Interface())
return nil
},
}
func init() {
SettingCmd.AddCommand(SetCmd)
}