Skip to content

Commit

Permalink
Merge pull request #66 from rubiojr/rubiojr/nicer-error
Browse files Browse the repository at this point in the history
Nicer error message if missing configuration
  • Loading branch information
rneatherway committed May 24, 2024
2 parents 8b1c7f7 + 2d65963 commit 2d8d997
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion cmd/gh-slack/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package cmd

import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/cli/go-gh/pkg/config"
"github.com/spf13/cobra"
Expand All @@ -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 = `
Expand Down
2 changes: 1 addition & 1 deletion cmd/gh-slack/cmd/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 2d8d997

Please sign in to comment.