Skip to content

Commit

Permalink
Merge pull request #28 from mah0x211/add-global-option
Browse files Browse the repository at this point in the history
Add option to install globally
  • Loading branch information
mah0x211 authored Sep 28, 2023
2 parents a336335 + 89e25cd commit f76c7fe
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
run: make test

- name: Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,25 @@ $ lenv help
lenv - lua version manager
Usage:
lenv help Show this message
lenv setup Set up required files and directories
lenv path Show the configured paths
lenv fetch Fetch remote versions
lenv vers List available versions
lenv ls List installed versions
lenv install <version> <opt...> Install and use a <version> of lua
lenv install-lj <version> <opt...> Install and use a <version> of luajit
lenv install-rocks <version> Install and use a <version> of lurocks in
current lua environment
lenv use <version> Use a <version> of lua
lenv use-lj <version> Use a <version> of luajit
lenv use-rocks <version> Use a <version> of luajit
lenv <option> <command> [<args>...]
Options:
-g, --global Use /usr/local/lenv as installation directory
Commands:
help Show this message
setup Set up required files and directories
path Show the configured paths
fetch Fetch remote versions
vers List available versions
ls List installed versions
install <version> <opt...> Install and use a <version> of lua
install-lj <version> <opt...> Install and use a <version> of luajit
install-rocks <version> Install and use a <version> of lurocks in
current lua environment
use <version> Use a <version> of lua
use-lj <version> Use a <version> of luajit
use-rocks <version> Use a <version> of luajit
Note:
The <version> specifier of the above commands can be specified as follows;
Expand All @@ -59,9 +65,9 @@ Usage:
; luarocks
lenv install :latest ; that picks the the latest version of luarocks
lenv uninstall <version> Uninstall a <version> of lua
lenv uninstall-lj <version> Uninstall a <version> of luajit
lenv uninstall-rocks <version> Uninstall a <version> of luarocks
uninstall <version> Uninstall a <version> of lua
uninstall-lj <version> Uninstall a <version> of luajit
uninstall-rocks <version> Uninstall a <version> of luarocks
```

Expand Down
1 change: 0 additions & 1 deletion fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type ParseFunc func(v interface{}) *Versions

var (
ReLuaRocksVer = regexp.MustCompile(`(?si)href="(luarocks-([^"]+?)\.tar\.gz).*?href="(luarocks-[^"]+?\.tar\.gz\.asc)"`)
ReLuaJitVer = regexp.MustCompile(`(?i)([0-9a-f]+?)\s+(LuaJIT-([^\s]+?)\.tar\.gz)`)
ReLuaVer = regexp.MustCompile(`(?si)<tr>\s*<td class="name"><a href="(lua-([^"]+?)\.tar\.gz).+?class="sum">([0-9a-f]+)</td>\s*</tr>`)
)

Expand Down
38 changes: 22 additions & 16 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@ func CmdHelp(rc int, msgs ...interface{}) {
lenv - lua version manager
Usage:
lenv help Show this message
lenv setup Set up required files and directories
lenv path Show the configured paths
lenv fetch Fetch remote versions
lenv vers List available versions
lenv ls List installed versions
lenv install <version> <opt...> Install and use a <version> of lua
lenv install-lj <version> <opt...> Install and use a <version> of luajit
lenv install-rocks <version> Install and use a <version> of lurocks in
current lua environment
lenv use <version> Use a <version> of lua
lenv use-lj <version> Use a <version> of luajit
lenv use-rocks <version> Use a <version> of luajit
lenv <option> <command> [<args>...]
Options:
-g, --global Use /usr/local/lenv as installation directory
Commands:
help Show this message
setup Set up required files and directories
path Show the configured paths
fetch Fetch remote versions
vers List available versions
ls List installed versions
install <version> <opt...> Install and use a <version> of lua
install-lj <version> <opt...> Install and use a <version> of luajit
install-rocks <version> Install and use a <version> of lurocks in
current lua environment
use <version> Use a <version> of lua
use-lj <version> Use a <version> of luajit
use-rocks <version> Use a <version> of luajit
Note:
The <version> specifier of the above commands can be specified as follows;
Expand All @@ -48,9 +54,9 @@ Usage:
; luarocks
lenv install :latest ; that picks the the latest version of luarocks
lenv uninstall <version> Uninstall a <version> of lua
lenv uninstall-lj <version> Uninstall a <version> of luajit
lenv uninstall-rocks <version> Uninstall a <version> of luarocks
uninstall <version> Uninstall a <version> of lua
uninstall-lj <version> Uninstall a <version> of luajit
uninstall-rocks <version> Uninstall a <version> of luarocks
`)
osExit(rc)
}
53 changes: 36 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ var (
}
)

func init_global_vars(inst_globally bool) {
// get current working directory
wd, err := os.Getwd()
if err != nil {
fatalf("failed to getwd(): %v", err)
}
CWD = wd

if inst_globally {
// set LenvDir to /usr/local/lenv
LenvDir = filepath.Join("/usr/local/lenv")
}

SrcDir = filepath.Join(LenvDir, "src")
CurrentDir = filepath.Join(LenvDir, "current")
CurrentUsed = ""

LuaCfg.RootDir = filepath.Join(LenvDir, "lua")
LuaCfg.VersionFile = filepath.Join(LenvDir, "lua_vers.txt")
LuaJitCfg.RepoDir = filepath.Join(SrcDir, "luajit")
LuaJitCfg.RootDir = filepath.Join(LenvDir, "luajit")
LuaJitCfg.VersionFile = filepath.Join(LenvDir, "luajit_vers.txt")
LuaRocksCfg.VersionFile = filepath.Join(LenvDir, "luarocks_vers.txt")

ResolveCurrentDir()
}

func eprintf(format string, v ...interface{}) {
os.Stderr.WriteString(fmt.Sprintf(format, v...))
os.Stderr.Write([]byte{'\n'})
Expand Down Expand Up @@ -238,18 +265,21 @@ func CheckLuaRocksRootDir() {

func start() {
argv := os.Args[1:]
if len(argv) == 0 {
CmdHelp(0)
if len(argv) > 0 {
inst_globally := argv[0] == "-g" || argv[0] == "--global"
if inst_globally {
argv = argv[1:]
}
init_global_vars(inst_globally)
}

if argv[0] != "setup" {
if len(argv) == 0 || argv[0] == "help" {
CmdHelp(0)
} else if argv[0] != "setup" {
checkInitialized()
}

switch argv[0] {
case "help":
CmdHelp(0)

case "setup":
CmdSetup()

Expand Down Expand Up @@ -364,17 +394,6 @@ func ResolveCurrentDir() {
}
}

func init() {
// get current working directory
wd, err := os.Getwd()
if err != nil {
fatalf("failed to getwd(): %v", err)
}
CWD = wd

ResolveCurrentDir()
}

func main() {
wg := sync.WaitGroup{}
wg.Add(1)
Expand Down

0 comments on commit f76c7fe

Please sign in to comment.