Short and single-letter names in application code become full words (tests keep theirs). Wrapped calls, signatures and composite literals put one item per line, and one-line function bodies are expanded. Exported names and groups of constants get doc comments, and comments refer to the renamed identifiers.
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
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("command persistent pre-run", "command", "config.get")
|
|
},
|
|
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
|
slog.Debug("command persistent post-run", "command", "config.get")
|
|
},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
slog.Debug("command run", "command", "config.get")
|
|
|
|
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)
|
|
}
|
|
|
|
value, err := conf.ValueOf(args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
kind, _ := conf.TypeOf(args[0])
|
|
fmt.Println(value, "<"+kind.String()+">")
|
|
|
|
return nil
|
|
},
|
|
}
|
|
return cmd
|
|
}
|