✨ Add option to print config from config command
This commit is contained in:
parent
17a1cf1ade
commit
b7eaf941fb
1 changed files with 20 additions and 1 deletions
|
|
@ -22,12 +22,13 @@ import (
|
|||
fp "path/filepath"
|
||||
|
||||
"codeberg.org/danjones000/my-log/config"
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var ConfigCmd = &cobra.Command{
|
||||
Use: "config",
|
||||
Short: "Save default config to file",
|
||||
Short: "Save default config to file, or print the current config value",
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
print, _ := cmd.Flags().GetBool("print")
|
||||
|
|
@ -35,6 +36,24 @@ var ConfigCmd = &cobra.Command{
|
|||
fmt.Fprintln(cmd.OutOrStdout(), config.DefaultPath())
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
v, _ := config.RetrieveFromContext(cmd.Context())
|
||||
val := v.Get(args[0])
|
||||
var out []byte
|
||||
if val == nil {
|
||||
out = []byte("<nil>")
|
||||
} else {
|
||||
var err error
|
||||
out, err = toml.Marshal(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(cmd.OutOrStdout(), string(out))
|
||||
return nil
|
||||
}
|
||||
|
||||
force, _ := cmd.Flags().GetBool("force")
|
||||
configPath := config.DefaultPath()
|
||||
if !force {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue