diff --git a/cmd/crowdsec-cli/config_feature_flags.go b/cmd/crowdsec-cli/config_feature_flags.go index ed672711f..838d8a0c1 100644 --- a/cmd/crowdsec-cli/config_feature_flags.go +++ b/cmd/crowdsec-cli/config_feature_flags.go @@ -2,10 +2,12 @@ package main import ( "fmt" + "path/filepath" "github.com/fatih/color" "github.com/spf13/cobra" + "github.com/crowdsecurity/crowdsec/pkg/csconfig" "github.com/crowdsecurity/crowdsec/pkg/fflag" ) @@ -87,7 +89,14 @@ func runConfigFeatureFlags(cmd *cobra.Command, args []string) error { fmt.Println("To enable a feature you can: ") fmt.Println(" - set the environment variable CROWDSEC_FEATURE_ to true") - fmt.Printf(" - add the line '- ' to the file %s/feature.yaml\n", csConfig.ConfigPaths.ConfigDir) + + featurePath, err := filepath.Abs(csconfig.GetFeatureFilePath(ConfigFilePath)) + if err != nil { + // we already read the file, shouldn't happen + return err + } + + fmt.Printf(" - add the line '- ' to the file %s\n", featurePath) fmt.Println() if len(enabled) == 0 && len(disabled) == 0 { diff --git a/pkg/csconfig/fflag.go b/pkg/csconfig/fflag.go index 444585fb8..7311f9e75 100644 --- a/pkg/csconfig/fflag.go +++ b/pkg/csconfig/fflag.go @@ -18,12 +18,18 @@ func LoadFeatureFlagsEnv(logger *log.Logger) error { return nil } -// LoadFeatureFlags parses feature.yaml to enable feature flags. +// FeatureFlagsFileLocation returns the path to the feature.yaml file. // The file is in the same directory as config.yaml, which is provided // as the fist parameter. This can be different than ConfigPaths.ConfigDir -func LoadFeatureFlagsFile(configPath string, logger *log.Logger) error { +// because we have not read config.yaml yet so we don't know the value of ConfigDir. +func GetFeatureFilePath(configPath string) string { dir := filepath.Dir(configPath) - featurePath := filepath.Join(dir, "feature.yaml") + return filepath.Join(dir, "feature.yaml") +} + +// LoadFeatureFlags parses feature.yaml to enable feature flags. +func LoadFeatureFlagsFile(configPath string, logger *log.Logger) error { + featurePath := GetFeatureFilePath(configPath) if err := fflag.Crowdsec.SetFromYamlFile(featurePath, logger); err != nil { return fmt.Errorf("file %s: %s", featurePath, err)