-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovider.go
More file actions
89 lines (68 loc) · 3.81 KB
/
provider.go
File metadata and controls
89 lines (68 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Package runtime defines the provider interface and registry for runtime managers
package runtime
// ShimProvider defines the minimal interface needed by the shim executable.
// This interface excludes heavy operations like Install() and ListAvailable()
// that require net/http and other dependencies not needed for shim execution.
type ShimProvider interface {
// Name returns the name of the runtime (e.g., "python", "node", "ruby")
Name() string
// DisplayName returns a human-readable name (e.g., "Python", "Node.js", "Ruby")
DisplayName() string
// Shims returns the list of shim executable names this runtime provides
// For example, Python returns ["python", "python3", "pip", "pip3"]
// Node.js returns ["node", "npm", "npx"]
Shims() []string
// ExecutablePath returns the path to the main executable for a given version
// For example, for Python 3.11.0, this might return "/path/to/python3.11"
ExecutablePath(version string) (string, error)
// IsInstalled checks if a specific version is installed
IsInstalled(version string) (bool, error)
// ShouldReshimAfter checks if the given command should trigger a reshim.
// Returns true if the command installs or uninstalls global packages that add/remove executables.
// The shimName parameter indicates which shim was invoked (e.g., "npm", "pip")
// The args parameter contains the command arguments (e.g., ["install", "-g", "typescript"])
ShouldReshimAfter(shimName string, args []string) bool
}
// Provider defines the full interface that all runtime providers must implement.
// It embeds ShimProvider and adds operations that require heavier dependencies.
type Provider interface {
ShimProvider
// Install downloads and installs a specific version of the runtime
Install(version string) error
// Uninstall removes an installed version of the runtime
Uninstall(version string) error
// ListInstalled returns all installed versions of this runtime
ListInstalled() ([]InstalledVersion, error)
// ListAvailable returns all available versions that can be installed
// This might query online sources or use cached data
ListAvailable() ([]AvailableVersion, error)
// InstallPath returns the installation directory for a given version
InstallPath(version string) (string, error)
// GlobalVersion returns the globally configured version, if any
GlobalVersion() (string, error)
// SetGlobalVersion sets the global default version
SetGlobalVersion(version string) error
// LocalVersion returns the locally configured version for the current directory
// This reads from dtvem.config.json
LocalVersion() (string, error)
// SetLocalVersion sets the local version for the current directory
SetLocalVersion(version string) error
// CurrentVersion returns the currently active version
// (checks local first, then global)
CurrentVersion() (string, error)
// DetectInstalled scans the system for existing installations of this runtime
// Returns a list of detected versions with their paths and sources
DetectInstalled() ([]DetectedVersion, error)
// GlobalPackages detects globally installed packages for a specific installation
// Takes the installation path and returns a list of package names
// Returns empty slice if the runtime doesn't support global packages
GlobalPackages(installPath string) ([]string, error)
// InstallGlobalPackages reinstalls global packages to a specific version
// Takes the version and list of package names to install
// Returns nil if the runtime doesn't support global packages
InstallGlobalPackages(version string, packages []string) error
// ManualPackageInstallCommand returns the command string for manually installing packages
// Used to provide help text to users if automatic package installation fails
// Returns empty string if the runtime doesn't support global packages
ManualPackageInstallCommand(packages []string) string
}