root

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:   "add",
	Short: "add root by user id",
	Long:  `add root by user id`,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		return bootstrap.New(bootstrap.WithContext(cmd.Context())).Add(
			bootstrap.InitDiscardLog,
			bootstrap.InitConfig,
			bootstrap.InitDatabase,
		).Run()
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("missing user id")
		}
		u, err := db.GetUserByID(args[0])
		if err != nil {
			fmt.Printf("get user failed: %s", err)
			return nil
		}
		if err := db.AddRoot(u); err != nil {
			fmt.Printf("add root failed: %s", err)
			return nil
		}
		fmt.Printf("add root success: %s\n", u.Username)
		return nil
	},
}
View Source
var RemoveCmd = &cobra.Command{
	Use:   "remove",
	Short: "remove",
	Long:  `remove root`,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		return bootstrap.New(bootstrap.WithContext(cmd.Context())).Add(
			bootstrap.InitDiscardLog,
			bootstrap.InitConfig,
			bootstrap.InitDatabase,
		).Run()
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("missing user id")
		}
		u, err := db.GetUserByID(args[0])
		if err != nil {
			fmt.Printf("get user failed: %s", err)
			return nil
		}
		if err := db.RemoveRoot(u); err != nil {
			fmt.Printf("remove root failed: %s", err)
			return nil
		}
		fmt.Printf("remove root success: %s\n", u.Username)
		return nil
	},
}
View Source
var RootCmd = &cobra.Command{
	Use:   "root",
	Short: "root",
	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 root",
	Long:  `show root`,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		return bootstrap.New(bootstrap.WithContext(cmd.Context())).Add(
			bootstrap.InitDiscardLog,
			bootstrap.InitConfig,
			bootstrap.InitDatabase,
		).Run()
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		roots := db.GetRoots()
		for _, root := range roots {
			fmt.Printf("id: %s\tusername: %s\n", root.ID, root.Username)
		}
		return nil
	},
}

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