mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 20:07:52 +02: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
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/ddworken/hishtory/client/hctx"
|
"github.com/ddworken/hishtory/client/hctx"
|
||||||
"github.com/ddworken/hishtory/client/lib"
|
"github.com/ddworken/hishtory/client/lib"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -12,7 +14,7 @@ var enableCmd = &cobra.Command{
|
|||||||
GroupID: GROUP_ID_CONFIG,
|
GroupID: GROUP_ID_CONFIG,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
ctx := hctx.MakeContext()
|
ctx := hctx.MakeContext()
|
||||||
lib.CheckFatalError(lib.Enable(ctx))
|
lib.CheckFatalError(Enable(ctx))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,10 +24,22 @@ var disableCmd = &cobra.Command{
|
|||||||
GroupID: GROUP_ID_CONFIG,
|
GroupID: GROUP_ID_CONFIG,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
ctx := hctx.MakeContext()
|
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() {
|
func init() {
|
||||||
rootCmd.AddCommand(enableCmd)
|
rootCmd.AddCommand(enableCmd)
|
||||||
rootCmd.AddCommand(disableCmd)
|
rootCmd.AddCommand(disableCmd)
|
||||||
|
@ -492,18 +492,6 @@ func IsEnabled(ctx *context.Context) (bool, error) {
|
|||||||
return hctx.GetConf(ctx).IsEnabled, nil
|
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) {
|
func CheckFatalError(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, filename, line, _ := runtime.Caller(1)
|
_, filename, line, _ := runtime.Caller(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user