Adds fetch to slp
This commit is contained in:
parent
b95b203a1e
commit
986af2d5ec
8
TODO.md
8
TODO.md
|
@ -1,6 +1,4 @@
|
|||
- Maybe add `fetch` command to download the current registry
|
||||
- If so, stop downloading it with most requests
|
||||
- If it has been more than x amount of time, print a notice to the user if they try to install or upgrade something without fetching, but let them proceed with their action... just a nag message
|
||||
- Add versioning: `flag@0.2.0`? May require more language support in slope to deal with programs wanting to use various versions on the same system
|
||||
- Have `gen` build out a readme skeleton
|
||||
|
||||
- Add support for an install.json file, which slp can process to install non-library code:
|
||||
- Dependencies: []
|
||||
- slope version required
|
||||
|
|
7
main.go
7
main.go
|
@ -14,6 +14,7 @@ const (
|
|||
banner string = "\033[32;1mslp - slope package manager\033[0m"
|
||||
helptext string = `
|
||||
slp docs [[-g]] [module] # open a module's readme in $PAGER
|
||||
slp fetch # fetches the updated registry
|
||||
slp gen # creates new module dir/skeleton
|
||||
slp help # print usage information
|
||||
slp install [[-g]] [module...] # installs module(s)
|
||||
|
@ -59,6 +60,12 @@ func main() {
|
|||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
case "fetch":
|
||||
err := operators.Fetch()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
case "list":
|
||||
err := operators.List()
|
||||
if err != nil {
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package operators
|
||||
|
||||
func Fetch() error {
|
||||
err := downloadTheDirectory()
|
||||
|
||||
return err
|
||||
}
|
|
@ -95,6 +95,17 @@ func Generate() error {
|
|||
sf.WriteString(fmt.Sprintf("(define %s-hello-world (lambda ()\n", opts.Title))
|
||||
sf.WriteString(fmt.Sprintf(" (display \"'Hello, world!' from %s\\n\")))\n\n; vim: ts=2 sw=2 expandtab ft=slope\n", opts.Title))
|
||||
|
||||
rm, err := os.Create(filepath.Join(dir, "README.md"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rm.Close()
|
||||
rm.WriteString("# ")
|
||||
rm.WriteString(opts.Title)
|
||||
rm.WriteString("\n\n")
|
||||
rm.WriteString(opts.Description)
|
||||
rm.WriteString("\n\n")
|
||||
|
||||
fmt.Printf("\nPackage \033[1m%q\033[0m has been created!\n", opts.Title)
|
||||
|
||||
return nil
|
||||
|
|
|
@ -21,9 +21,9 @@ func Install(pkg string, global bool) error {
|
|||
return fmt.Errorf(" \033[2m└\033[0m \033[91mError:\033[0m package %q is already installed", pkg)
|
||||
}
|
||||
|
||||
err = downloadTheDirectory()
|
||||
err = checkRegistry()
|
||||
if err != nil {
|
||||
return fmt.Errorf(" \033[2m└\033[0m \033[91mError:\033[0m could not retrieve remote package registry")
|
||||
return fmt.Errorf(" \033[2m└\033[0m \033[91mError:\033[0m %s", err.Error())
|
||||
}
|
||||
|
||||
packages, err := getPackages()
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
func Search(val string) error {
|
||||
err := downloadTheDirectory()
|
||||
err := checkRegistry()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ func Show(pkg string) error {
|
|||
if _, err := os.Stat(path); err != nil {
|
||||
// If the package is not locally available
|
||||
// get it from the registry
|
||||
err := downloadTheDirectory()
|
||||
err := checkRegistry()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
// package, to ensure it is up to date
|
||||
func Update(pkg string, global bool) error {
|
||||
// Get remote data
|
||||
err := downloadTheDirectory()
|
||||
err := checkRegistry()
|
||||
if err != nil {
|
||||
return fmt.Errorf(" \033[2m└\033[0m \033[91mError:\033[0m could not retrieve remote package registry")
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
// "time"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -66,15 +66,23 @@ func getModBaseDir() string {
|
|||
return p
|
||||
}
|
||||
|
||||
func downloadTheDirectory() error {
|
||||
func checkRegistry() error {
|
||||
modDir := getModBaseDir()
|
||||
path := filepath.Join(modDir, "package.json")
|
||||
|
||||
// Only get a new file every, at most, 15 minutes
|
||||
// f, err := os.Stat(path)
|
||||
// if err == nil && f.ModTime().Before(time.Now().Add(-15 * time.Minute)) {
|
||||
// return nil
|
||||
// }
|
||||
f, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("The registry is not present on the system. Run: `slp fetch`")
|
||||
} else if f.ModTime().Before(time.Now().Add(-7 * 24 * time.Hour)) {
|
||||
fmt.Fprint(os.Stderr, "You have not run `slp fetch` in more than 7 days: consider updating the package list\n")
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func downloadTheDirectory() error {
|
||||
modDir := getModBaseDir()
|
||||
path := filepath.Join(modDir, "package.json")
|
||||
|
||||
resp, err := http.Get(packageListURL)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue