Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Jan 5, 2025
1 parent 71cde77 commit 0566464
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
17 changes: 8 additions & 9 deletions commands/config_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,22 @@ func getExecutableDir(cmd *cobra.Command) (string, error) {
return alt.FindBinDir()
}

func validateUserProvidedDir(path string) (string, error) {
abs, err := filepath.Abs(path)
func validateUserProvidedDir(path string) (normalized string, err error) {
normalized, err = filepath.Abs(path)
if err != nil {
return "", err
return
}
path = abs

lstat, err := os.Lstat(path)
lstat, err := os.Lstat(normalized)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return "", fmt.Errorf("directory not found: %s", path)
err = fmt.Errorf("directory not found: %s", normalized)
}
return "", err
return
}
if !lstat.IsDir() {
return "", fmt.Errorf("%s is not a directory", path)
err = fmt.Errorf("not a directory: %s", normalized)
}

return path, nil
return
}
23 changes: 8 additions & 15 deletions internal/config/alt/alt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package alt

import (
"runtime"
"strings"

"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -42,22 +41,16 @@ func (a *Alt) GenerateAndSave() error {

func (a *Alt) generateExecutable() string {
if runtime.GOOS == "windows" {
return withLineEnding("\r\n", "@echo off",
":: "+a.comment,
`set "CLI_CONFIG_FILE=`+a.configPath+`"`,
a.target+" %*",
)
return "@echo off\r\n" +
":: " + a.comment + "\r\n" +
`set "CLI_CONFIG_FILE=` + a.configPath + `"` + "\r\n" +
a.target + " %*\r\n"
}

return withLineEnding("\n", "#!/bin/sh",
"# "+a.comment,
"export CLI_CONFIG_FILE="+a.configPath,
a.target+` "$@"`,
)
}

func withLineEnding(e string, lines ...string) string {
return strings.Join(lines, e) + e
return "#!/bin/sh\n" +
"# " + a.comment + "\n" +
"export CLI_CONFIG_FILE=" + a.configPath + "\n" +
a.target + ` "$@"` + "\n"
}

func GetExecutableFileExtension() string {
Expand Down
2 changes: 1 addition & 1 deletion internal/config/alt/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func Update(ctx context.Context, cnf *config.Config, debugLog func(fmt string, i
}
if !newCnfStruct.Metadata.UpdatedAt.IsZero() &&
!newCnfStruct.Metadata.UpdatedAt.After(cnf.Metadata.UpdatedAt) {
debugLog("Config is already up to date (updated at %v)", cnf.Metadata.UpdatedAt)
debugLog("Config is already up to date (updated at %v)", cnf.Metadata.UpdatedAt.Format(time.RFC3339))
return nil
}
if newCnfStruct.Metadata.Version != "" {
Expand Down

0 comments on commit 0566464

Please sign in to comment.