Move code out of lib that is only referenced for one command

This commit is contained in:
David Dworken 2022-11-19 17:06:28 -08:00
parent 343f3cf1e5
commit d9c4a59ddd
No known key found for this signature in database
2 changed files with 16 additions and 14 deletions

View File

@ -1,6 +1,8 @@
package cmd
import (
"context"
"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"
"github.com/spf13/cobra"
@ -12,7 +14,7 @@ var enableCmd = &cobra.Command{
GroupID: GROUP_ID_CONFIG,
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
lib.CheckFatalError(lib.Enable(ctx))
lib.CheckFatalError(Enable(ctx))
},
}
@ -22,10 +24,22 @@ var disableCmd = &cobra.Command{
GroupID: GROUP_ID_CONFIG,
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
lib.CheckFatalError(lib.Disable(ctx))
lib.CheckFatalError(Disable(ctx))
},
}
func Enable(ctx *context.Context) error {
config := hctx.GetConf(ctx)
config.IsEnabled = true
return hctx.SetConfig(config)
}
func Disable(ctx *context.Context) error {
config := hctx.GetConf(ctx)
config.IsEnabled = false
return hctx.SetConfig(config)
}
func init() {
rootCmd.AddCommand(enableCmd)
rootCmd.AddCommand(disableCmd)

View File

@ -492,18 +492,6 @@ func IsEnabled(ctx *context.Context) (bool, error) {
return hctx.GetConf(ctx).IsEnabled, nil
}
func Enable(ctx *context.Context) error {
config := hctx.GetConf(ctx)
config.IsEnabled = true
return hctx.SetConfig(config)
}
func Disable(ctx *context.Context) error {
config := hctx.GetConf(ctx)
config.IsEnabled = false
return hctx.SetConfig(config)
}
func CheckFatalError(err error) {
if err != nil {
_, filename, line, _ := runtime.Caller(1)