-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Look for the config files relative to the path.config flag #2245
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ var ( | |
// The default config cannot include the beat name as it is not initialized | ||
// when this variable is created. See ChangeDefaultCfgfileFlag which should | ||
// be called prior to flags.Parse(). | ||
configfiles = flagArgList("c", "beat.yml", "Configuration file `path`") | ||
configfiles = flagArgList("c", "beat.yml", "Configuration file, relative to path.config") | ||
overwrites = common.NewFlagConfig(nil, nil, "E", "Configuration overwrite") | ||
testConfig = flag.Bool("configtest", false, "Test configuration and exit.") | ||
|
||
|
@@ -29,7 +29,8 @@ var ( | |
}) | ||
|
||
// home-path CLI flag (initialized in init) | ||
homePath *string | ||
homePath *string | ||
configPath *string | ||
) | ||
|
||
func init() { | ||
|
@@ -39,7 +40,7 @@ func init() { | |
} | ||
|
||
homePath = makePathFlag("path.home", "Home path") | ||
makePathFlag("path.config", "Configuration path") | ||
configPath = makePathFlag("path.config", "Configuration path") | ||
makePathFlag("path.data", "Data path") | ||
makePathFlag("path.logs", "Logs path") | ||
} | ||
|
@@ -55,15 +56,7 @@ func mustNewConfigFrom(from interface{}) *common.Config { | |
// ChangeDefaultCfgfileFlag replaces the value and default value for the `-c` | ||
// flag so that it reflects the beat name. | ||
func ChangeDefaultCfgfileFlag(beatName string) error { | ||
path, err := filepath.Abs(filepath.Dir(os.Args[0])) | ||
if err != nil { | ||
return fmt.Errorf("Failed to set default config file location because "+ | ||
"the absolute path to %s could not be obtained. %v", | ||
os.Args[0], err) | ||
} | ||
|
||
path = filepath.Join(path, beatName+".yml") | ||
configfiles.SetDefault(path) | ||
configfiles.SetDefault(beatName + ".yml") | ||
return nil | ||
} | ||
|
||
|
@@ -105,9 +98,27 @@ func Load(path string) (*common.Config, error) { | |
var config *common.Config | ||
var err error | ||
|
||
cfgpath := "" | ||
if *configPath != "" { | ||
cfgpath = *configPath | ||
} else if *homePath != "" { | ||
cfgpath = *homePath | ||
} | ||
|
||
if path == "" { | ||
config, err = common.LoadFiles(configfiles.list...) | ||
list := []string{} | ||
for _, cfg := range configfiles.list { | ||
if !filepath.IsAbs(cfg) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, still works :-) |
||
list = append(list, filepath.Join(cfgpath, cfg)) | ||
} else { | ||
list = append(list, cfg) | ||
} | ||
} | ||
config, err = common.LoadFiles(list...) | ||
} else { | ||
if !filepath.IsAbs(path) { | ||
path = filepath.Join(cfgpath, path) | ||
} | ||
config, err = common.LoadFile(path) | ||
} | ||
if err != nil { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An absolute path also works, correct?