Files
job-search/internal/cli/config/show.go
T
bwilliams e19c8c2b69 Imports split into three groups: standard library, third-party, then this project's own packages
gci is configured with the sections standard, default and localmodule, and
goimports with the module path as its local prefix, so both formatters
agree.
2026-10-14 17:40:06 +01:00

45 lines
1.0 KiB
Go

package config
import (
"fmt"
"log/slog"
"github.com/spf13/cobra"
"git.avsdev.uk/Go/job-search/internal/cli"
)
func commandShow(opts *cli.Options) *cobra.Command {
cmd := &cobra.Command{
Use: "show",
Short: "Print config information",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
slog.Debug("config.show.PersistentPreRun")
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
slog.Debug("config.show.PersistentPostRun")
},
RunE: func(cmd *cobra.Command, args []string) error {
slog.Debug("config.show.Run")
conf, err := opts.RunSetup(cmd, true, true)
if err != nil {
return fmt.Errorf("no configuration loaded (%w)", err)
}
if yaml, _ := cmd.Flags().GetBool("yaml"); yaml {
conf.PrintYaml()
} else if json, _ := cmd.Flags().GetBool("json"); json {
conf.PrintJson()
} else {
conf.PrintTerminal()
}
return nil
},
}
cmd.Flags().Bool("json", false, "format configuration as json")
cmd.Flags().Bool("yaml", false, "format configuration as yaml")
return cmd
}