mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-15 01:22:43 +02:00
Add initial cobra implementation for config-*
This commit is contained in:
51
client/cmd/configAdd.go
Normal file
51
client/cmd/configAdd.go
Normal file
@ -0,0 +1,51 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/ddworken/hishtory/client/hctx"
|
||||
"github.com/ddworken/hishtory/client/lib"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var configAddCmd = &cobra.Command{
|
||||
Use: "config-add",
|
||||
Short: "Add a config option",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmd.Help()
|
||||
},
|
||||
}
|
||||
|
||||
var addCustomColumnsCmd = &cobra.Command{
|
||||
Use: "custom-columns",
|
||||
Short: "Add a custom column",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
columnName := args[0]
|
||||
command := args[1]
|
||||
ctx := hctx.MakeContext()
|
||||
config := hctx.GetConf(ctx)
|
||||
if config.CustomColumns == nil {
|
||||
config.CustomColumns = make([]hctx.CustomColumnDefinition, 0)
|
||||
}
|
||||
config.CustomColumns = append(config.CustomColumns, hctx.CustomColumnDefinition{ColumnName: columnName, ColumnCommand: command})
|
||||
lib.CheckFatalError(hctx.SetConfig(config))
|
||||
},
|
||||
}
|
||||
|
||||
var addDisplayedColumnsCmd = &cobra.Command{
|
||||
Use: "displayed-columns",
|
||||
Short: "Add a column to be displayed",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx := hctx.MakeContext()
|
||||
config := hctx.GetConf(ctx)
|
||||
vals := args
|
||||
config.DisplayedColumns = append(config.DisplayedColumns, vals...)
|
||||
lib.CheckFatalError(hctx.SetConfig(config))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(configAddCmd)
|
||||
configAddCmd.AddCommand(addCustomColumnsCmd)
|
||||
configAddCmd.AddCommand(addDisplayedColumnsCmd)
|
||||
}
|
Reference in New Issue
Block a user