44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"git.avsdev.uk/Go/job-search/internal/cli"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
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
|
|
}
|