diff --git a/cmd/gh-slack/cmd/root.go b/cmd/gh-slack/cmd/root.go index 4d4a41a..e109ba0 100644 --- a/cmd/gh-slack/cmd/root.go +++ b/cmd/gh-slack/cmd/root.go @@ -1,7 +1,10 @@ package cmd import ( + "fmt" "os" + "path/filepath" + "strings" "github.com/cli/go-gh/pkg/config" "github.com/spf13/cobra" @@ -18,7 +21,22 @@ func getFlagOrElseConfig(cfg *config.Config, flags *pflag.FlagSet, key string) ( return value, nil } - return cfg.Get([]string{"extensions", "slack", key}) + + return getGHSlackConfigValue(cfg, key) +} + +func getGHSlackConfigValue(cfg *config.Config, key string) (string, error) { + fullKey := []string{"extensions", "slack", key} + s, err := cfg.Get(fullKey) + if err != nil { + return "", fmt.Errorf( + "failed to read gh-slack configuration value %q from %q: %w", + strings.Join(fullKey, "."), + filepath.Join(config.ConfigDir(), "config.yml"), + err) + } + + return s, nil } const sendConfigEample = ` diff --git a/cmd/gh-slack/cmd/send.go b/cmd/gh-slack/cmd/send.go index 964ab91..8ec3407 100644 --- a/cmd/gh-slack/cmd/send.go +++ b/cmd/gh-slack/cmd/send.go @@ -46,7 +46,7 @@ var sendCmd = &cobra.Command{ } if wait && bot == "" { - bot, err = cfg.Get([]string{"extensions", "slack", "bot"}) + bot, err = getGHSlackConfigValue(cfg, "bot") if err != nil { return err }