mirror of
https://github.com/ddworken/hishtory.git
synced 2025-02-22 21:41:01 +01:00
Move code out of lib that is only referenced for one command
This commit is contained in:
parent
343f3cf1e5
commit
d9c4a59ddd
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user