Add option to print config from config command

This commit is contained in:
Dan Jones 2026-03-09 16:45:18 -05:00
commit b7eaf941fb

View file

@ -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 {