Adds local install option
This commit is contained in:
parent
92376101c3
commit
b95b203a1e
|
@ -11,12 +11,15 @@ slp help # print usage information
|
|||
slp install [[-g]] [module...] # installs module(s)
|
||||
slp installed [[-g]] # lists all installed packages
|
||||
slp list # lists all available packages
|
||||
slp local [[-g]] [filepath] # installs the module at filepath
|
||||
slp remove [[-g]] [module...] # removes module(s)
|
||||
slp search [term...] # searches for modules
|
||||
slp show [module...] # shows details for module(s)
|
||||
slp update [[-g]] [module...] # updates module(s)
|
||||
```
|
||||
|
||||
The above options are more or less self-explanatory with the exception of `local`. `local` will install a module that you have on your system, but not on the slope module path. This is useful if, for example, a person has made their module available but it is not in the slp registry. In which case you can clone their repo and run `slp local ~/path/to/their-module`. Once installed in this manner the slp `remove`, `installed`, and `docs` commands will be able to operate on the module based on its folder name. `update`, however, requires the registry to know what git tag is the current/newest tag.
|
||||
|
||||
## Global installs
|
||||
|
||||
Operations that accept a -g flag will attempt to install a module systemwide (this may require root access). A --global flag may be passed in lieu of a -g flag if desired for clarity.
|
||||
|
|
14
main.go
14
main.go
|
@ -19,6 +19,7 @@ slp help # print usage information
|
|||
slp install [[-g]] [module...] # installs module(s)
|
||||
slp installed [[-g]] # lists all installed packages
|
||||
slp list # lists all available packages
|
||||
slp local [[-g]] [filepath] # installs the module at filepath
|
||||
slp remove [[-g]] [module...] # removes module(s)
|
||||
slp search [term...] # searches for modules
|
||||
slp show [module...] # shows details for module(s)
|
||||
|
@ -64,6 +65,19 @@ func main() {
|
|||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
case "local":
|
||||
locals := make([]string, 0, 5)
|
||||
for _, mod := range modules {
|
||||
fmt.Printf("installing from local %s%s\n", mod, globalTxt)
|
||||
err := operators.LocalInstall(mod, global)
|
||||
if err != nil {
|
||||
fmt.Printf(" \033[2m└\033[0m \033[31mERROR:\033[0m %s\n\n", err.Error())
|
||||
continue
|
||||
}
|
||||
locals = append(locals, mod)
|
||||
fmt.Print(" \033[2m└\033[0m \033[32mdone\033[0m\n\n")
|
||||
}
|
||||
printStat("\033[1;32m", "LOCALED", locals)
|
||||
case "installed":
|
||||
if len(arg) > 2 && (arg[2] == "-g" || arg[2] == "--global") {
|
||||
global = true
|
||||
|
|
58
operators/local.go
Normal file
58
operators/local.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
package operators
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
requiredFileCount int = 2
|
||||
)
|
||||
|
||||
func LocalInstall(path string, global bool) error {
|
||||
modDir := GlobalPath
|
||||
if !global {
|
||||
modDir = getModBaseDir()
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(ExpandedAbsFilepath(path))
|
||||
if err != nil {
|
||||
return fmt.Errorf(" \033[2m└\033[0m \033[91mError:\033[0m %q does not exist or is not accessible", path)
|
||||
}
|
||||
|
||||
filesFound := 0
|
||||
for _, file := range files {
|
||||
switch strings.ToLower(file.Name()) {
|
||||
case "module.json":
|
||||
filesFound++
|
||||
case "main.slo":
|
||||
filesFound++
|
||||
}
|
||||
}
|
||||
|
||||
if filesFound < requiredFileCount {
|
||||
return fmt.Errorf(" \033[2m└\033[0m \033[91mError:\033[0m %q does not contain the required files for a module", path)
|
||||
}
|
||||
|
||||
pkg := filepath.Base(path)
|
||||
if pkg == "/" || pkg == "" || pkg[0] == '.' {
|
||||
return fmt.Errorf(" \033[2m└\033[0m \033[91mError:\033[0m %q is not a valid package name", pkg)
|
||||
}
|
||||
|
||||
_, err = os.Stat(filepath.Join(modDir, pkg))
|
||||
if err == nil {
|
||||
return fmt.Errorf(" \033[2m└\033[0m \033[91mError:\033[0m package %q is already installed", pkg)
|
||||
}
|
||||
|
||||
cmd := exec.Command("cp", "-r", ExpandedAbsFilepath(path), modDir)
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf(" \033[2m└\033[0m \033[91mError:\033[0m could not install to the module folder")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue
Block a user