hishtory/client/cmd/enableDisable.go

47 lines
965 B
Go
Raw Normal View History

2022-11-15 04:26:56 +01:00
package cmd
import (
"context"
2022-11-15 04:26:56 +01:00
"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"
"github.com/spf13/cobra"
)
var enableCmd = &cobra.Command{
Use: "enable",
Short: "Enable hiSHtory recording",
GroupID: GROUP_ID_CONFIG,
2022-11-15 04:26:56 +01:00
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
lib.CheckFatalError(Enable(ctx))
2022-11-15 04:26:56 +01:00
},
}
var disableCmd = &cobra.Command{
Use: "disable",
Short: "Disable hiSHtory recording",
GroupID: GROUP_ID_CONFIG,
2022-11-15 04:26:56 +01:00
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
lib.CheckFatalError(Disable(ctx))
2022-11-15 04:26:56 +01:00
},
}
2023-09-05 21:45:17 +02:00
func Enable(ctx context.Context) error {
config := hctx.GetConf(ctx)
config.IsEnabled = true
return hctx.SetConfig(config)
}
2023-09-05 21:45:17 +02:00
func Disable(ctx context.Context) error {
config := hctx.GetConf(ctx)
config.IsEnabled = false
return hctx.SetConfig(config)
}
2022-11-15 04:26:56 +01:00
func init() {
rootCmd.AddCommand(enableCmd)
rootCmd.AddCommand(disableCmd)
}