Skip to content

Commit

Permalink
update reading from configs
Browse files Browse the repository at this point in the history
Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan committed Jun 13, 2024
1 parent ea78273 commit f2a876f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
39 changes: 26 additions & 13 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -1505,9 +1505,22 @@ func (a *analyzeCommand) writeProvConfig(tempDir string, config []provider.Confi
}

func (a *analyzeCommand) getProviderOptions(tempDir string, provConfig []provider.Config, prov string) error {
var confDir string
var set bool
ops := runtime.GOOS
if ops == "linux" {
confDir, set = os.LookupEnv("XDG_CONFIG_HOME")
}
if ops != "linux" || confDir == "" || !set {
// on Unix, including macOS, this returns the $HOME environment variable. On Windows, it returns %USERPROFILE%
var err error
confDir, err = os.UserHomeDir()
if err != nil {
return err
}
}
// get provider options from provider settings file
home := os.Getenv("HOME")
data, err := os.ReadFile(filepath.Join(home, ".kantra", fmt.Sprintf("%v.json", prov)))
data, err := os.ReadFile(filepath.Join(confDir, ".kantra", fmt.Sprintf("%v.json", prov)))
if err != nil {
return err
}
Expand Down Expand Up @@ -1546,18 +1559,18 @@ func (a *analyzeCommand) mergeProviderConfig(defaultConf, optionsConf []provider
if conf.Proxy != nil {
seen[conf.Name].Proxy = conf.Proxy
}
// set init config options
for i, init := range conf.InitConfig {
if len(init.AnalysisMode) != 0 {
seen[conf.Name].InitConfig[i].AnalysisMode = init.AnalysisMode
}
if len(init.ProviderSpecificConfig) != 0 {
provSpecificConf, err := a.mergeProviderSpecificConfig(init.ProviderSpecificConfig, seen[conf.Name].InitConfig[i].ProviderSpecificConfig, tempDir)
if err != nil {
return nil, err
}
seen[conf.Name].InitConfig[i].ProviderSpecificConfig = provSpecificConf
}
// set init config options
for i, init := range conf.InitConfig {
if len(init.AnalysisMode) != 0 {
seen[conf.Name].InitConfig[i].AnalysisMode = init.AnalysisMode
}
if len(init.ProviderSpecificConfig) != 0 {
provSpecificConf, err := a.mergeProviderSpecificConfig(init.ProviderSpecificConfig, seen[conf.Name].InitConfig[i].ProviderSpecificConfig, tempDir)
if err != nil {
return nil, err
}
seen[conf.Name].InitConfig[i].ProviderSpecificConfig = provSpecificConf
}
}
}
Expand Down
18 changes: 11 additions & 7 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
## Provider Options

The supported providers have several options to utilize. Examples of the available
options can be found [here](../provider_options.json.sample). To read about each of these options,
options can be found [here](../java.json.sample) and [here](../golang.json.sample). To read about each of these options,
see the analyzer provider [documentation](https://github.com/konveyor/analyzer-lsp/blob/main/docs/providers.md).

Kantra will look for these options at `$HOME/.kantra/<provider_name>.json`
Current providers included are:
- java
- golang
- python
- nodejs
Kantra will look for these options at:
- Linux: `$XDG_CONFIG_HOME/.kantra/<provider_name>.json` and then `$HOME/.kantra/<provider_name>.json`
- MacOS: `$HOME/.kantra/<provider_name>.json`
- Windows: `%USERPROFILE%/.kantra/<provider_name>.json`

Current supported providers are:
- java
- golang
- python
- nodejs

0 comments on commit f2a876f

Please sign in to comment.