Skip to content

Commit

Permalink
config: Add better help text for config (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
craftamap committed Nov 25, 2021
1 parent 1b20feb commit b6bf947
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
14 changes: 12 additions & 2 deletions cmd/commands/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/craftamap/bb/cmd/options"
"github.com/craftamap/bb/config"
Expand All @@ -21,7 +22,16 @@ func Add(rootCmd *cobra.Command, _ *options.GlobalOptions) {
configCommand := cobra.Command{
Use: "config",
Short: "configure bb",
Long: "configure bb",
Long: fmt.Sprintf(`configure bb and change it's behaviour.
bb sources configuration values from multiple sources:
1. The global configuration (usually located at $HOME/.config/bb/configuration.toml)
2. The local configuration (a .bb file in your repository root)
3. Environment variables
4. command-line flags
This command allows you to modify and retrieve the configuration values without editing the configuration values by yourself.
The following keys are supported:
%s`, strings.Join(config.ConfigKeys, ", ")),
PreRunE: func(_ *cobra.Command, _ []string) error {
if Get && GetAll {
logging.Error("--get and --get-all are mutually exclusive")
Expand Down Expand Up @@ -49,7 +59,7 @@ func Add(rootCmd *cobra.Command, _ *options.GlobalOptions) {
},
}

configCommand.Flags().BoolVar(&Local, "local", false, "local allows to modify the local configuration")
configCommand.Flags().BoolVar(&Local, "local", false, "modify or retrieve the local configuration")
configCommand.Flags().BoolVar(&Get, "get", false, "gets a configuration value instead of setting it")
configCommand.Flags().BoolVar(&GetAll, "get-all", false, "prints out all configuration values of the selected configuration")

Expand Down
3 changes: 0 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,4 @@ func initConfig() {
viper.RegisterAlias("remote", configuration.CONFIG_KEY_GIT_REMOTE)
viper.RegisterAlias("git_protocol", configuration.CONFIG_KEY_REPO_CLONE_GIT_PROTOCOL)
viper.RegisterAlias("sync-method", configuration.CONFIG_KEY_PR_SYNC_SYNC_METHOD)

logging.Debugf("%+v", viper.AllSettings())

}
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ const (
CONFIG_KEY_PR_SYNC_SYNC_METHOD = "pr.sync.sync_method"
)

var ConfigKeys = []string{
CONFIG_KEY_AUTH_USERNAME,
CONFIG_KEY_AUTH_PASSWORD,
CONFIG_KEY_GIT_REMOTE,
CONFIG_KEY_REPO_CLONE_GIT_PROTOCOL,
CONFIG_KEY_PR_SYNC_SYNC_METHOD,
}

type Validator func(interface{}) (interface{}, error)

// Enum is just a string of a list.
Expand Down

0 comments on commit b6bf947

Please sign in to comment.