Skip to content

Commit

Permalink
Remove uninstall-lj and uninstall-rocks commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mah0x211 committed Apr 5, 2024
1 parent d8a500d commit 54a9b78
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ Commands:
If the version of luarocks is specified along with the version of lua, the
operation will target the specified version of the lua environment.
Otherwise, the operation will target the current lua environment.
In the case of the 'uninstall' command, the version specifier must match the
target version exactly. Also, if the version of luarocks is specified along
with the version of lua, the version specifier of luarocks is ignored.
`)
osExit(rc)
}
2 changes: 1 addition & 1 deletion install.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func doInstall(cfg *TargetConfig, item *VerItem, opts []string) {
}

func CmdInstall(opts []string) {
target := PickTargetVersion(opts[0])
target := PickTargetVersion(opts[0], false)
if target.Lua != nil {
doInstall(target.Lua.Config, target.Lua.Version, opts[1:])
}
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ type TargetVersion struct {
LuaRocks *Target
}

func PickTargetVersion(vers string) *TargetVersion {
func PickTargetVersion(vers string, exactMatch bool) *TargetVersion {
// check target version
if len(vers) == 0 || vers == ":" {
CmdHelp(1, "no version specified")
Expand All @@ -292,21 +292,21 @@ func PickTargetVersion(vers string) *TargetVersion {
// if `lj-' prefix is specified, then the target is LuaJIT version
target.Lua = &Target{
Config: LuaJitCfg,
Version: PickTargetVersionItem(LuaJitCfg, vers[3:]),
Version: PickTargetVersionItem(LuaJitCfg, vers[3:], exactMatch),
}
} else {
// otherwise the target is Lua version.
target.Lua = &Target{
Config: LuaCfg,
Version: PickTargetVersionItem(LuaCfg, vers),
Version: PickTargetVersionItem(LuaCfg, vers, exactMatch),
}
}
}

if len(rocksVer) > 0 {
target.LuaRocks = &Target{
Config: LuaRocksCfg,
Version: PickTargetVersionItem(LuaRocksCfg, rocksVer),
Version: PickTargetVersionItem(LuaRocksCfg, rocksVer, exactMatch),
}
}

Expand Down
2 changes: 1 addition & 1 deletion uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func uninstall(t *Target) {
}

func CmdUninstall(opts []string) {
target := PickTargetVersion(opts[0])
target := PickTargetVersion(opts[0], true)

// uninstall the specified version of lua
if target.Lua != nil {
Expand Down
2 changes: 1 addition & 1 deletion use.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func UseInstalledVersion(cfg *TargetConfig, ver string) {
}

func CmdUse(opts []string) {
target := PickTargetVersion(opts[0])
target := PickTargetVersion(opts[0], false)
if target.Lua != nil {
UseInstalledVersion(target.Lua.Config, target.Lua.Version.Ver)
}
Expand Down
10 changes: 8 additions & 2 deletions vers.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,20 @@ func ListTargetVersions(cfg *TargetConfig) string {
return b.String()
}

func PickTargetVersionItem(cfg *TargetConfig, ver string) *VerItem {
func PickTargetVersionItem(cfg *TargetConfig, ver string, exactMatch bool) *VerItem {
print("check %s version %q definition ... ", cfg.Name, ver)
vers, err := NewVersionsFromFile(cfg.VersionFile)
if err != nil {
fatalf("failed to read version file %q: %v", cfg.VersionFile, err)
}

item := vers.PickItem(ver)
var item *VerItem
if exactMatch {
item = vers.GetItem(ver)
} else {
item = vers.PickItem(ver)
}

if item == nil {
printf("not found")
fatalf("%s version %q does not defined in %q\n%s", cfg.Name, ver, cfg.VersionFile, ListTargetVersions(cfg))
Expand Down

0 comments on commit 54a9b78

Please sign in to comment.