Skip to content

Commit

Permalink
return error if no home direcotory found
Browse files Browse the repository at this point in the history
  • Loading branch information
corylanou committed Sep 16, 2024
1 parent 62b04bf commit 02d32ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 5 additions & 1 deletion cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ func (c *Cmd) Execute(ctx context.Context, doc *Document) error {
copy(args, c.Args)
for i, arg := range args {
if strings.HasPrefix(arg, "~") {
args[i] = filepath.Join(homeDirectory(), arg[1:])
hd, err := homeDirectory()
if err != nil {
return c.newError(err)
}
args[i] = filepath.Join(hd, arg[1:])
}
}

Expand Down
9 changes: 4 additions & 5 deletions home.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package hype

import (
"log"
"os"
)

// homeDirectory retursn the home directory of the current user
// it only runs once
var homeDir string

func homeDirectory() string {
func homeDirectory() (string, error) {
if homeDir != "" {
return homeDir
return homeDir, nil
}

hd, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
return "", err
}
homeDir = hd
return homeDir
return homeDir, nil
}

0 comments on commit 02d32ac

Please sign in to comment.