Skip to content
Closed
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
1 change: 1 addition & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func newCmd() *cmd {
commands.Env,
commands.Config,
commands.Cd,
commands.Path,
}

return &cmd{app: app, version: version}
Expand Down
67 changes: 67 additions & 0 deletions cmd/commands/path.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2025 Han Li and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package commands

import (
"fmt"
"strings"

"github.com/urfave/cli/v2"
"github.com/version-fox/vfox/internal"
"github.com/version-fox/vfox/internal/base"
)

var Path = &cli.Command{
Name: "path",
Usage: "Show the absolute path of an installed SDK",
UsageText: "vfox path <sdk>@<version>",
Action: pathCmd,
Category: CategorySDK,
}

func pathCmd(ctx *cli.Context) error {
args := ctx.Args()
if args.First() == "" {
return cli.Exit("sdk name and version are required (e.g. nodejs@24)", 1)
}

sdkArg := args.First()
argArr := strings.Split(sdkArg, "@")
if len(argArr) != 2 {
return cli.Exit("invalid format, expected <sdk>@<version> (e.g. nodejs@24)", 1)
}

name := strings.ToLower(argArr[0])
version := base.Version(argArr[1])

manager := internal.NewSdkManager()
defer manager.Close()

source, err := manager.LookupSdk(name)
if err != nil {
fmt.Println("notfound")
return nil
}

if source.CheckExists(version) {
fmt.Println(source.VersionPath(version))
} else {
fmt.Println("notfound")
}

return nil
}
17 changes: 17 additions & 0 deletions cmd/commands/path_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package commands

import (
"testing"
)

func TestPathCommand(t *testing.T) {
// This is a placeholder test for the path command
// In a real implementation, we would test the actual command logic
if Path.Name != "path" {
t.Errorf("Expected command name to be 'path', got '%s'", Path.Name)
}

if Path.Usage != "Show the absolute path of an installed SDK" {
t.Errorf("Expected usage to be 'Show the absolute path of an installed SDK', got '%s'", Path.Usage)
}
}
Loading