Updates slp to have a more normalized syntax and updates surrounding documentation
This commit is contained in:
parent
308b24ab9e
commit
e99e818b37
26
README.md
26
README.md
|
@ -5,21 +5,19 @@ SLope Package manager.
|
|||
An easy way to install, remove, and update slope packages.
|
||||
|
||||
```
|
||||
slp +<package> # installs a package
|
||||
slp -<package> # removes a package
|
||||
slp ^<package> # updates a package
|
||||
slp ?<term> # searches for a package
|
||||
slp @<package> # shows details for a package
|
||||
|
||||
slp docs [module] # opens the modules readme in $PAGER
|
||||
slp gen # creates a new package
|
||||
slp help # print this message
|
||||
slp installed # lists all installed packages
|
||||
slp list # lists all available packages
|
||||
slp docs [module] # open a module's readme in $PAGER
|
||||
slp gen # creates new module dir/skeleton
|
||||
slp help # print usage information
|
||||
slp install [module...] # installs module(s)
|
||||
slp installed # lists all installed packages
|
||||
slp list # lists all available packages
|
||||
slp remove [module...] # removes module(s)
|
||||
slp search [term...] # searches for modules
|
||||
slp show [module...] # shows details module(s)
|
||||
slp update [module...] # updates module(s)
|
||||
```
|
||||
|
||||
Prefix operations can be chained (e.g. `slp +foo -bar`...)
|
||||
|
||||
|
||||
Packages can be registered in the repository at [https://git.rawtext.club/slope-lang/packages](slope-lang/packages) by submitting a PR to that repository
|
||||
|
||||
_A note on module versioning_: At present, **slp** does not handle any versioning and will always grab the newest version of a module, while `update` will always update to the newest. There are plans in place to declare a module release via the release's tag value: `module-name@tag` (ex. ini@0.2.1). Stay tuned for an announcement that that has been added. In the meantime: good fortune and safe journeys in the wilderness.
|
||||
|
||||
|
|
151
main.go
151
main.go
|
@ -5,24 +5,23 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"git.rawtext.club/slope-lang/slp/args"
|
||||
"git.rawtext.club/slope-lang/slp/operators"
|
||||
)
|
||||
|
||||
const (
|
||||
helptext string = `slp - slope package manager
|
||||
|
||||
slp +<package> # installs a package
|
||||
slp -<package> # removes a package
|
||||
slp ^<package> # updates a package
|
||||
slp ?<term> # searches for a package
|
||||
slp @<package> # shows details for a package
|
||||
slp docs [module] # open a module's readme in $PAGER
|
||||
slp gen # creates new module dir/skeleton
|
||||
slp help # print usage information
|
||||
slp install [module...] # installs module(s)
|
||||
slp installed # lists all installed packages
|
||||
slp list # lists all available packages
|
||||
slp remove [module...] # removes module(s)
|
||||
slp search [term...] # searches for modules
|
||||
slp show [module...] # shows details module(s)
|
||||
slp update [module...] # updates module(s)
|
||||
|
||||
slp docs [module] # opens the modules readme in $PAGER
|
||||
slp gen # creates a new package
|
||||
slp help # print this message
|
||||
slp installed # lists all installed packages
|
||||
slp list # lists all available packages
|
||||
`
|
||||
)
|
||||
|
||||
|
@ -30,7 +29,6 @@ func main() {
|
|||
arg := os.Args
|
||||
if len(arg) <= 1 {
|
||||
fmt.Println(helptext)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -39,100 +37,97 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
if arg[1] == "docs" {
|
||||
switch arg[1] {
|
||||
case "docs":
|
||||
if len(arg) < 3 {
|
||||
fmt.Println("The 'docs' command requires a module name as an argument: `slp docs [module]`")
|
||||
}
|
||||
fmt.Printf("Retrieving docs for %q", arg[2])
|
||||
err := operators.ReadDocs(arg[2])
|
||||
if err != nil {
|
||||
fmt.Println(" \033[31m- done\033[0m" )
|
||||
fmt.Println(" \033[31m- done\033[0m")
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Print(" \033[32m- done\033[0m\n")
|
||||
return
|
||||
}
|
||||
|
||||
if arg[1] == "list" {
|
||||
case "list":
|
||||
err := operators.List()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if arg[1] == "installed" {
|
||||
case "installed":
|
||||
err := operators.ShowInstalled()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if arg[1] == "gen" {
|
||||
case "gen":
|
||||
err := operators.Generate()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
ops, err := args.Parse(arg[1:])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
installs []string
|
||||
removes []string
|
||||
updates []string
|
||||
)
|
||||
|
||||
for _, op := range ops {
|
||||
var err error
|
||||
|
||||
switch op.Type {
|
||||
case args.INSTALL:
|
||||
fmt.Printf("installing %s", op.Package)
|
||||
err = operators.Install(op.Package)
|
||||
installs = append(installs, op.Package)
|
||||
case args.REMOVE:
|
||||
fmt.Printf("removing %s", op.Package)
|
||||
err = operators.Remove(op.Package)
|
||||
removes = append(removes, op.Package)
|
||||
case args.UPDATE:
|
||||
fmt.Printf("updating %s", op.Package)
|
||||
err = operators.Update(op.Package)
|
||||
updates = append(updates, op.Package)
|
||||
case args.SEARCH:
|
||||
fmt.Printf("searching for %q\n\n", op.Package)
|
||||
err = operators.Search(op.Package)
|
||||
goto isError
|
||||
case args.SHOW:
|
||||
fmt.Printf("showing details for %q\n\n", op.Package)
|
||||
err = operators.Show(op.Package)
|
||||
goto isError
|
||||
case "install":
|
||||
installs := make([]string, 0, 5)
|
||||
for _, mod := range arg[2:] {
|
||||
fmt.Printf("installing %s", mod)
|
||||
err := operators.Install(mod)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
installs = append(installs, mod)
|
||||
}
|
||||
|
||||
fmt.Print(" \033[32m- done\033[0m\n")
|
||||
|
||||
isError:
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
fmt.Print(" \033[32m- done\033[0m\n\n")
|
||||
printStat("\033[1;32m", "INSTALLED", installs)
|
||||
case "remove":
|
||||
removes := make([]string, 0, 5)
|
||||
for _, mod := range arg[2:] {
|
||||
fmt.Printf("removing %s", mod)
|
||||
err := operators.Remove(mod)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
removes = append(removes, mod)
|
||||
}
|
||||
fmt.Print(" \033[32m- done\033[0m\n\n")
|
||||
printStat("\033[1;31m", "REMOVED", removes)
|
||||
case "update":
|
||||
updates := make([]string, 0, 5)
|
||||
for _, mod := range arg[2:] {
|
||||
fmt.Printf("updating %s", mod)
|
||||
err := operators.Update(mod)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
updates = append(updates, mod)
|
||||
}
|
||||
fmt.Print(" \033[32m- done\033[0m\n\n")
|
||||
printStat("\033[1;36m", "UPDATED", updates)
|
||||
case "search":
|
||||
for _, term := range arg[2:] {
|
||||
fmt.Printf("searching for %q\n\n", term)
|
||||
err := operators.Search(term)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
case "show":
|
||||
for _, mod := range arg[2:] {
|
||||
fmt.Printf("showing details for %q\n\n", mod)
|
||||
err := operators.Show(mod)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "Unknown command %s\n\n%s\n", arg[1], helptext)
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
|
||||
printStat("\033[1;32m", "INSTALLED", installs)
|
||||
printStat("\033[1;31m", "REMOVED", removes)
|
||||
printStat("\033[1;36m", "UPDATED", updates)
|
||||
}
|
||||
|
||||
func printStat(color, prefix string, pkgs []string) {
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"regexp"
|
||||
)
|
||||
|
||||
|
||||
func Search(val string) error {
|
||||
err := downloadTheDirectory()
|
||||
if err != nil {
|
||||
|
@ -18,15 +17,20 @@ func Search(val string) error {
|
|||
}
|
||||
|
||||
sorted := sortPackages(packages)
|
||||
found := 0
|
||||
|
||||
for _, p := range sorted {
|
||||
match, err := regexp.MatchString(fmt.Sprintf(".*%s.*", val), p.Title)
|
||||
match2, _ := regexp.MatchString(fmt.Sprintf(".*%s.*", val), p.Description)
|
||||
if err == nil && (match || match2) {
|
||||
fmt.Println(packageString(p))
|
||||
found++
|
||||
}
|
||||
}
|
||||
|
||||
if found == 0 {
|
||||
fmt.Print(" \033[31m0 modules found\033[0m\n\n")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
44
slp.1
44
slp.1
|
@ -1,4 +1,4 @@
|
|||
.TH "slp" 1 "20 AUG 2021" "" "General Operation Manual"
|
||||
.TH "slp" 1 "16 SEP 2021" "" "General Operation Manual"
|
||||
.SH NAME
|
||||
\fBslp\fP - (sl)ope (p)ackage manager
|
||||
.SH SYNOPSIS
|
||||
|
@ -8,48 +8,48 @@
|
|||
.fam T
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
\fBslp\fP is a basic package management system for the slope programming language.
|
||||
\fBslp\fP is a basic package management system for the slope programming language
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B
|
||||
\fBhelp\fP
|
||||
Display usage help and exit. Provides a list of all command line options with a short description and exits.
|
||||
.TP
|
||||
.B
|
||||
\fBlist\fP
|
||||
Display a list of \fIall\fP packages in the registry
|
||||
\fBdocs [module]\fP
|
||||
View the given module's README file, if one exists. Only works for local modules. Uses \fI$PAGER\fP, falling back to \fIless\fP, as the document viewer
|
||||
.TP
|
||||
.B
|
||||
\fBgen\fP
|
||||
Generate a new project folder with module.json and main.slo files
|
||||
.TP
|
||||
.B
|
||||
\fBhelp\fP
|
||||
Display usage help and exit. Provides a list of all command line options with a short description and exits
|
||||
.TP
|
||||
.B
|
||||
\fBinstall [module...]\fP
|
||||
Installs the given modules
|
||||
.TP
|
||||
.B
|
||||
\fBinstalled\fP
|
||||
Display a list of the \fIcurrently installed\fP modules
|
||||
.TP
|
||||
.B
|
||||
\fBdocs [module]\fP
|
||||
View the given module's README file, if one exists. Only works for local modules
|
||||
\fBlist\fP
|
||||
Display a list of \fIall\fP packages in the registry
|
||||
.TP
|
||||
.B
|
||||
\fB+<package>\fP
|
||||
Installs \fI<package>\fP
|
||||
\fBremove [module...]\fP
|
||||
Removes the given modules
|
||||
.TP
|
||||
.B
|
||||
\fB-<package>\fP
|
||||
Removes \fI<package>\fP
|
||||
\fBsearch [term...]\fP
|
||||
Searches for the given terms in the package registry and displays matching results
|
||||
.TP
|
||||
.B
|
||||
\fB^<package>\fP
|
||||
Updates \fI<package>\fP
|
||||
\fBshow [module...]\fP
|
||||
Show information about the given modules
|
||||
.TP
|
||||
.B
|
||||
\fB@<package>\fP
|
||||
Show information about \fI<package>\fP
|
||||
.TP
|
||||
.B
|
||||
\fB?<term>\fP
|
||||
Searches for \fI<term>\fP in the package registry and displays matching results
|
||||
\fBupdate [module...]\fP
|
||||
Updates the given modules to the newest available version
|
||||
.SH BUGS
|
||||
There are bugs. Have fun!
|
||||
.SH LINKS
|
||||
|
|
Loading…
Reference in New Issue