Skip to content
Open
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
51 changes: 0 additions & 51 deletions .github/workflows/claude-dev.yml

This file was deleted.

110 changes: 101 additions & 9 deletions cmd/commands/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,29 @@ package commands

import (
"fmt"
"path/filepath"
"strings"
"text/template"

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

var Info = &cli.Command{
Name: "info",
Usage: "Show plugin info",
Action: infoCmd,
Category: CategoryPlugin,
Name: "info",
Usage: "Show plugin info or SDK path",
ArgsUsage: "[<sdk> | <sdk>@<version>]",
Action: infoCmd,
Category: CategoryPlugin,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "format",
Aliases: []string{"f"},
Usage: "Format the output using the given Go template",
},
},
}

func infoCmd(ctx *cli.Context) error {
Expand All @@ -38,23 +50,103 @@ func infoCmd(ctx *cli.Context) error {
if args == "" {
return cli.Exit("invalid arguments", 1)
}

// Check if the argument is in the format <sdk>@<version>
if strings.Contains(args, "@") {
argArr := strings.Split(args, "@")
if len(argArr) == 2 {
name := strings.ToLower(argArr[0])
version := base.Version(argArr[1])

// Check for empty SDK name or version
if name != "" && string(version) != "" {
sdk, err := manager.LookupSdk(name)
if err != nil {
if ctx.IsSet("format") {
// For template output, we still need to output something
data := struct {
Name string
Version string
Path string
}{
Name: name,
Version: string(version),
Path: "notfound",
}
return executeTemplate(ctx, data)
}
fmt.Println("notfound")
return nil
}

path := ""
if sdk.CheckExists(version) {
path = filepath.Join(sdk.VersionPath(version), fmt.Sprintf("%s-%s", name, version))
} else {
path = "notfound"
}

// Check if format flag is set
formatValue := ctx.String("format")
if formatValue != "" {
data := struct {
Name string
Version string
Path string
}{
Name: name,
Version: string(version),
Path: path,
}
return executeTemplate(ctx, data)
}

fmt.Println(path)
return nil
}
}
}

// Show plugin info
s, err := manager.LookupSdk(args)
if err != nil {
return fmt.Errorf("%s not supported, error: %w", args, err)
}
source := s.Plugin

// If format flag is set, prepare data for template
if ctx.IsSet("format") {
data := struct {
Name string
Version string
Homepage string
InstallPath string
Description string
}{
Name: source.Name,
Version: source.Version,
Homepage: source.Homepage,
InstallPath: s.InstallPath,
Description: source.Description,
}
return executeTemplate(ctx, data)
}

pterm.Println("Plugin Info:")
pterm.Println("Name ", "->", pterm.LightBlue(source.Name))
pterm.Println("Version ", "->", pterm.LightBlue(source.Version))
pterm.Println("Homepage", "->", pterm.LightBlue(source.Homepage))
pterm.Println("Desc ", "->")
pterm.Println(pterm.LightBlue(source.Description))
if len(source.LegacyFilenames) == 0 {
pterm.Println("Legacy Files ->", pterm.LightRed("None"))
} else {
pterm.Println("Legacy Files ->", pterm.LightBlue(source.LegacyFilenames))
}
source.ShowNotes()
return nil
}

func executeTemplate(ctx *cli.Context, data interface{}) error {
tmplStr := ctx.String("format")
tmpl, err := template.New("format").Parse(tmplStr)
if err != nil {
return fmt.Errorf("error parsing template: %w", err)
}
return tmpl.Execute(ctx.App.Writer, data)
}
Loading
Loading