Refactored main.go into cmd/jobsearch/main.go (in case separate commands are introduced later) which has required the options mechanism to change slightly as well as the logging.

This commit is contained in:
bwilliams committed 2026-10-09 09:29:42 +01:00
1 parent de3ebf68c5
commit 6436253629
14 files changed
+273 -224

No files matched your search

+6 -9
View File
@@ -29,7 +29,7 @@ import (
"github.com/spf13/viper"
)
func setConfig(conf config.JobSearchConfig, key string, value string) error {
func setConfig(conf *config.JobSearchConfig, key string, value string) error {
var confValue any = nil
var confType reflect.Kind
var err error
@@ -65,7 +65,7 @@ func setConfig(conf config.JobSearchConfig, key string, value string) error {
return nil
}
func unsetConfig(conf config.JobSearchConfig, key string) error {
func unsetConfig(conf *config.JobSearchConfig, key string) error {
if _, err := conf.TypeOf(key); err != nil {
return err
}
@@ -88,7 +88,7 @@ func unsetConfig(conf config.JobSearchConfig, key string) error {
return nil
}
func commandSet() *cobra.Command {
func commandSet(opts *cli.Options) *cobra.Command {
cmd := &cobra.Command{
Use: "set [config_key] [config_value]",
Args: cobra.MatchAll(cobra.MinimumNArgs(1), cobra.MaximumNArgs(2)),
@@ -117,9 +117,9 @@ func commandSet() *cobra.Command {
return err
}
conf, ok := cli.ConfigFromContext(cmd.Context())
if !ok {
return errors.New("no configuration loaded")
conf, err := opts.RunSetup(cmd, true, true)
if err != nil {
return fmt.Errorf("no configuration loaded (%w)", err)
}
if viper.ConfigFileUsed() == "" {
@@ -132,9 +132,6 @@ func commandSet() *cobra.Command {
return setConfig(conf, args[0], args[1])
}
},
Annotations: map[string]string{
"terminal_log": "1",
},
}
cmd.Flags().BoolP("unset", "x", false, "clear configuration setting")
return cmd