diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c92e03a..47bf42d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,12 @@ name: Test on: - push + push: + branches: + - '**' + paths-ignore: + - '**.md' + - 'LICENSE' jobs: test: diff --git a/README.md b/README.md index 8b9cd86..a032805 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Lua Version Manager. please run a `help` command to show the help message. -```sh +``` $ lenv help lenv - lua version manager @@ -42,7 +42,18 @@ Options: Commands: help Show this message setup Set up required files and directories - path Show the configured paths + path [] Show the configured paths + + Note: + The specifier of the above commands can be specified as follows; + + lenv path bin ; show the PATH of the current lua environment + lenv path lualib ; show the LUA_PATH of the current lua environment + lenv path luaclib ; show the LUA_CPATH of the current lua environment + + if is not specified, all the above paths of the current lua + environment will be shown. + fetch Fetch remote versions vers List available versions ls List installed versions @@ -71,7 +82,6 @@ Commands: uninstall Uninstall a of lua uninstall-lj Uninstall a of luajit uninstall-rocks Uninstall a of luarocks - ``` **NOTE: you must run a `fetch` command at the first. that command will crawling the version files of `Lua`, `LuaJIT` and `LuaRocks` immediately.** diff --git a/help.go b/help.go index 6da1baa..06f50f3 100644 --- a/help.go +++ b/help.go @@ -28,7 +28,18 @@ Options: Commands: help Show this message setup Set up required files and directories - path Show the configured paths + path Show the configured paths + + Note: + The specifier of the above commands can be specified as follows; + + lenv path bin ; show the PATH of the current lua environment + lenv path lualib ; show the LUA_PATH of the current lua environment + lenv path luaclib ; show the LUA_CPATH of the current lua environment + + if is not specified, all the above paths of the current lua + environment will be shown. + fetch Fetch remote versions vers List available versions ls List installed versions diff --git a/main.go b/main.go index 2ad21e3..f6f743f 100644 --- a/main.go +++ b/main.go @@ -284,7 +284,7 @@ func start() { CmdSetup() case "path": - CmdPath() + CmdPath(argv[1:]) case "fetch": CmdFetch() diff --git a/path.go b/path.go index fe05348..7c81420 100644 --- a/path.go +++ b/path.go @@ -6,7 +6,34 @@ import ( "strings" ) -func CmdPath() { +func get_luacpath() string { + prefix := filepath.Clean(CurrentDir+"/lua_modules/luaclib") + "/" + paths := []string{} + for i := 0; i <= 10; i++ { + dir := prefix + strconv.Itoa(i) + paths = append(paths, dir+"/?.so") + } + return strings.Join(paths, ";") + ";;" +} + +func get_luapath() string { + prefix := filepath.Clean(CurrentDir+"/lua_modules/lualib") + "/" + paths := []string{} + for i := 0; i <= 10; i++ { + dir := prefix + strconv.Itoa(i) + paths = append(paths, dir+"/?.lua", dir+"/?/init.lua") + } + return strings.Join(paths, ";") + ";;" +} + +func get_path() string { + return strings.Join([]string{ + filepath.Clean(CurrentDir + "/bin"), + filepath.Clean(CurrentDir + "/lua_modules/bin"), + }, ":") +} + +func printAll() { printf(` # # please add the following lenv settings to your environment @@ -14,41 +41,37 @@ func CmdPath() { `) for _, name := range []string{"PATH", "LUA_PATH", "LUA_CPATH"} { - var ( - format string - value string - ) - + var value string switch name { case "PATH": - format = `export %s="%s"` - value = strings.Join([]string{ - filepath.Clean(CurrentDir + "/bin"), - filepath.Clean(CurrentDir + "/lua_modules/bin"), - "$PATH", - }, ":") + value = get_path() + ":$PATH" case "LUA_PATH": - format = `export %s="%s;"` - prefix := filepath.Clean(CurrentDir+"/lua_modules/lualib") + "/" - paths := []string{} - for i := 0; i <= 10; i++ { - dir := prefix + strconv.Itoa(i) - paths = append(paths, dir+"/?.lua", dir+"/?/init.lua") - } - value = strings.Join(paths, ";") + ";" + value = get_luapath() case "LUA_CPATH": - format = `export %s="%s;"` - prefix := filepath.Clean(CurrentDir+"/lua_modules/luaclib") + "/" - paths := []string{} - for i := 0; i <= 10; i++ { - dir := prefix + strconv.Itoa(i) - paths = append(paths, dir+"/?.so") - } - value = strings.Join(paths, ";") + ";" + value = get_luacpath() } - printf(format, name, value) + printf(`export %s="%s"`, name, value) } printf("") } + +func CmdPath(opts []string) { + if len(opts) > 0 { + switch opts[0] { + case "bin": + printf(get_path()) + return + + case "lualib": + printf(get_luapath()) + return + + case "luaclib": + printf(get_luacpath()) + return + } + } + printAll() +} diff --git a/path_test.go b/path_test.go index 1e839b5..2a7cd4b 100644 --- a/path_test.go +++ b/path_test.go @@ -12,7 +12,7 @@ func Test_cmdPath(t *testing.T) { defer stdout.CloseAll() // test that cmdPath outputs PATH, LUA_PATH and LUA_CPATH to stdout - CmdPath() + CmdPath(nil) var b bytes.Buffer if _, err := b.ReadFrom(stdout.Close()); err != nil { t.Fatalf("failed to read from pipe: %v", err)