setting

package
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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
	},
}
View Source
var SettingCmd = &cobra.Command{
	Use:   "setting",
	Short: "setting",
	Long:  `you must first shut down the server, otherwise the changes will not take effect.`,
}
View Source
var ShowCmd = &cobra.Command{
	Use:   "show",
	Short: "show setting",
	Long:  `show 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 {
		m := make(map[model.SettingGroup]map[string]any)
		for g, s := range settings.GroupSettings {
			if _, ok := m[g]; !ok {
				m[g] = make(map[string]any)
			}
			for _, v := range s {
				m[g][v.Name()] = v.Interface()
			}
		}
		return yaml.NewEncoder(os.Stdout).Encode(m)
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL