Skip to content

Commit

Permalink
Add option to install globally
Browse files Browse the repository at this point in the history
  • Loading branch information
mah0x211 committed Sep 28, 2023
1 parent bde399a commit 21dfcdc
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 49 deletions.
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
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 21dfcdc

Please sign in to comment.