gci is configured with the sections standard, default and localmodule, and goimports with the module path as its local prefix, so both formatters agree.
47 lines
1001 B
Go
47 lines
1001 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"git.avsdev.uk/Go/job-search/internal/cli"
|
|
)
|
|
|
|
func commandGet(opts *cli.Options) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "get [config_key]",
|
|
Args: cobra.ExactArgs(1),
|
|
Short: "Get a value from configuration",
|
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
|
slog.Debug("config.get.PersistentPreRun")
|
|
},
|
|
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
|
slog.Debug("config.get.PersistentPostRun")
|
|
},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
slog.Debug("config.get.Run")
|
|
|
|
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
|
|
return err
|
|
}
|
|
|
|
conf, err := opts.RunSetup(cmd, true, true)
|
|
if err != nil {
|
|
return fmt.Errorf("no configuration loaded (%w)", err)
|
|
}
|
|
|
|
v, err := conf.ValueOf(args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
t, _ := conf.TypeOf(args[0])
|
|
fmt.Println(v, "<"+t.String()+">")
|
|
|
|
return nil
|
|
},
|
|
}
|
|
return cmd
|
|
}
|