Skip to content

Commit

Permalink
fix(config): replace ~ with HOME dir
Browse files Browse the repository at this point in the history
resolves #237
  • Loading branch information
JanDeDobbeleer committed Jan 6, 2025
1 parent 7c0d237 commit 95c6fcc
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package config

import (
"bytes"
"context"
context_ "context"
"fmt"
"io"
"net"
"net/http"
"os"
"path"
"runtime"
"strings"
"time"

"github.com/goccy/go-yaml"
"github.com/jandedobbeleer/aliae/src/context"
)

type httpClient interface {
Expand Down Expand Up @@ -73,11 +75,36 @@ func resolveConfigPath(configPath string) string {
configPath = path.Join(home(), ".aliae.yaml")
}

return configPath
return replaceTildePrefixWithHomeDir(configPath)
}

func replaceTildePrefixWithHomeDir(path string) string {
if !strings.HasPrefix(path, "~") {
return path
}

rem := path[1:]
if len(rem) == 0 || isSeparator(rem[0]) {
return home() + rem
}

return path
}

func isSeparator(c uint8) bool {
if c == '/' {
return true
}

if runtime.GOOS == context.WINDOWS && c == '\\' {
return true
}

return false
}

func getRemoteConfig(url string) (*Aliae, error) {
req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil)
req, err := http.NewRequestWithContext(context_.Background(), "GET", url, nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 95c6fcc

Please sign in to comment.