gci is configured with the sections standard, default and localmodule, and goimports with the module path as its local prefix, so both formatters agree.
45 lines
1.0 KiB
Go
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
|
|
}
|