Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ var (
// Verbose represents a debug flag for HTTP Exchanges
Verbose bool = false

ConfigPath = filepath.Join(os.Getenv("HOME"), ".microcks-cli", "config.yaml")
ConfigPath = defaultConfigPath()
)

func defaultConfigPath() string {
homeDir, err := getHomeDir()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if it's a dumb question, but where does this getHomeDir() method come from?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was in localconfig.go

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I would agree it's a bit confusing to be there and had the thought of whether move this into utility functions.

if err != nil {
return filepath.Join(".microcks-cli", "config.yaml")
}
return filepath.Join(homeDir, ".microcks-cli", "config.yaml")
}

// CreateTLSConfig wraps the creation of tls.Config object for use with HTTP Client for example.
func CreateTLSConfig() *tls.Config {
tlsConfig := &tls.Config{}
Expand Down
12 changes: 6 additions & 6 deletions pkg/config/localconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
import (
"fmt"
"os"
"path"
"path/filepath"
"slices"

configUtil "github.com/microcks/microcks-cli/pkg/util"
Expand Down Expand Up @@ -109,7 +109,7 @@ func DefaultConfigDir() (string, error) {
return "", nil
}

configDir = path.Join(homeDir, ".config", "microcks")
configDir = filepath.Join(homeDir, ".config", "microcks")

return configDir, nil
}
Expand All @@ -130,7 +130,7 @@ func DefaultLocalConfigPath() (string, error) {
if err != nil {
return "", err
}
return path.Join(dir, "config"), nil
return filepath.Join(dir, "config"), nil
}

// DefaultLocalWatchPath returns the local watch configuration path.
Expand All @@ -139,7 +139,7 @@ func DefaultLocalWatchPath() (string, error) {
if err != nil {
return "", err
}
return path.Join(dir, "watch"), nil
return filepath.Join(dir, "watch"), nil
}

// ValidateLocalConfig validates the local configuration.
Expand All @@ -155,7 +155,7 @@ func ValidateLocalConfig(config LocalConfig) error {

// WriteLocalConfig writes a new local configuration file.
func WriteLocalConfig(config LocalConfig, configPath string) error {
err := os.MkdirAll(path.Dir(configPath), os.ModePerm)
err := os.MkdirAll(filepath.Dir(configPath), os.ModePerm)
if err != nil {
return err
}
Expand Down Expand Up @@ -407,7 +407,7 @@ func ReadLocalWatchConfig(path string) (*WatchConfig, error) {

// WriteLocalWatchConfig writes a new local watch configuration file.
func WriteLocalWatchConfig(config WatchConfig, cfgPath string) error {
err := os.MkdirAll(path.Dir(cfgPath), os.ModePerm)
err := os.MkdirAll(filepath.Dir(cfgPath), os.ModePerm)
if err != nil {
return err
}
Expand Down