Skip to content

Commit

Permalink
support context
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Apr 16, 2023
1 parent f9fd5d4 commit 4ed6d32
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
_ "embed"
"flag"
"fmt"
Expand Down Expand Up @@ -61,9 +62,9 @@ func main() {

nodePath := ""
if *onlyPrint {
nodePath = node.GetNodePath(ver, nil)
nodePath = node.GetNodePath(context.Background(), ver, nil)
} else {
nodePath = node.GetNodePath(ver, log.New(os.Stdout, "", 0))
nodePath = node.GetNodePath(context.Background(), ver, log.New(os.Stdout, "", 0))
}

binPath := node.BinPath(nodePath)
Expand Down
4 changes: 3 additions & 1 deletion pkg/node/node.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package node

import (
"context"
"os"
"os/exec"
"path/filepath"
Expand All @@ -15,7 +16,7 @@ import (
var cacheDir = filepath.Join(fetchup.CacheDir(), "use-node")
var versionsFile = filepath.Join(cacheDir, "versions.json")

func GetNodePath(required string, logger fetchup.Logger) string {
func GetNodePath(ctx context.Context, required string, logger fetchup.Logger) string {
utils.E(os.MkdirAll(cacheDir, 0755))

n := getNodeInfo(required)
Expand All @@ -29,6 +30,7 @@ func GetNodePath(required string, logger fetchup.Logger) string {
_ = os.RemoveAll(nodePath)

fu := fetchup.New(nodePath, n.URLs()...)
fu.Ctx = ctx

if logger == nil {
fu.Logger = fetchup.LoggerQuiet
Expand Down
4 changes: 2 additions & 2 deletions pkg/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func TestGetVersion(t *testing.T) {
func TestGetNode(t *testing.T) {
g := got.T(t)

GetNodePath("", nil)
p := GetNodePath("", nil)
GetNodePath(g.Context(), "", nil)
p := GetNodePath(g.Context(), "", nil)

g.Has(p, "use-node")
}
Expand Down

0 comments on commit 4ed6d32

Please sign in to comment.