fix config home dir help text (#907)
## Type of change - [x] 🐛 Bugfix ## Issue(s) * #718 ## Test Plan - [x] 💪 Manual
This commit is contained in:
parent
acf1837e77
commit
e8473e3c78
@ -30,9 +30,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
configFilePath string
|
configFilePath string
|
||||||
configDir string
|
configFilePathFlag string
|
||||||
defaultDir string
|
configDir string
|
||||||
|
defaultDir string
|
||||||
|
displayDefaultFP = filepath.Join("$HOME", ".corso.toml")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Attempts to set the default dir and config file path.
|
// Attempts to set the default dir and config file path.
|
||||||
@ -64,13 +66,11 @@ func init() {
|
|||||||
// adds the persistent flag --config-file to the provided command.
|
// adds the persistent flag --config-file to the provided command.
|
||||||
func AddConfigFlags(cmd *cobra.Command) {
|
func AddConfigFlags(cmd *cobra.Command) {
|
||||||
fs := cmd.PersistentFlags()
|
fs := cmd.PersistentFlags()
|
||||||
|
fs.StringVar(
|
||||||
def := configFilePath
|
&configFilePathFlag,
|
||||||
if len(def) == 0 {
|
"config-file",
|
||||||
filepath.Join(defaultDir, ".corso.toml")
|
displayDefaultFP,
|
||||||
}
|
"config file location (default is $HOME/.corso.toml)")
|
||||||
|
|
||||||
fs.StringVar(&configFilePath, "config-file", def, "config file location (default is "+defaultDir+".corso.toml)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------
|
||||||
@ -81,7 +81,12 @@ func AddConfigFlags(cmd *cobra.Command) {
|
|||||||
// verifies that the configuration was able to read a file.
|
// verifies that the configuration was able to read a file.
|
||||||
func InitFunc() func(*cobra.Command, []string) error {
|
func InitFunc() func(*cobra.Command, []string) error {
|
||||||
return func(cmd *cobra.Command, args []string) error {
|
return func(cmd *cobra.Command, args []string) error {
|
||||||
err := initWithViper(GetViper(cmd.Context()), configFilePath)
|
fp := configFilePathFlag
|
||||||
|
if len(fp) == 0 || fp == displayDefaultFP {
|
||||||
|
fp = configFilePath
|
||||||
|
}
|
||||||
|
|
||||||
|
err := initWithViper(GetViper(cmd.Context()), fp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -94,7 +99,7 @@ func InitFunc() func(*cobra.Command, []string) error {
|
|||||||
// struct for testing.
|
// struct for testing.
|
||||||
func initWithViper(vpr *viper.Viper, configFP string) error {
|
func initWithViper(vpr *viper.Viper, configFP string) error {
|
||||||
// Configure default config file location
|
// Configure default config file location
|
||||||
if configFP == "" {
|
if configFP == "" || configFP == displayDefaultFP {
|
||||||
// Find home directory.
|
// Find home directory.
|
||||||
_, err := os.Stat(configDir)
|
_, err := os.Stat(configDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -170,8 +170,8 @@ func printFlags(buf *bytes.Buffer, flags *pflag.FlagSet) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.WriteString("|Flag|Short|Default|Help\n")
|
buf.WriteString("|Flag|Short|Default|Help|\n")
|
||||||
buf.WriteString("|:----|:-----|:-------|:----\n")
|
buf.WriteString("|:----|:-----|:-------|:----|\n")
|
||||||
|
|
||||||
flags.VisitAll(func(flag *pflag.Flag) {
|
flags.VisitAll(func(flag *pflag.Flag) {
|
||||||
if flag.Hidden {
|
if flag.Hidden {
|
||||||
@ -194,6 +194,6 @@ func printFlags(buf *bytes.Buffer, flags *pflag.FlagSet) {
|
|||||||
|
|
||||||
buf.WriteString("|")
|
buf.WriteString("|")
|
||||||
buf.WriteString(flag.Usage)
|
buf.WriteString(flag.Usage)
|
||||||
buf.WriteString("\n")
|
buf.WriteString("|\n")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user