forked from slope-lang/slope
parent
e1c49b4fb2
commit
ed1665f53d
@ -1,13 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Fmt(s string) {
|
||||
var out strings.Builder
|
||||
// exps := Parse(s)
|
||||
|
||||
fmt.Println(out.String())
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ModName(url, modDir string) string {
|
||||
base := path.Base(url)
|
||||
if strings.HasSuffix(base, ".git") {
|
||||
base = base[:len(base)-4]
|
||||
}
|
||||
|
||||
_, err := os.Stat(filepath.Join(modDir, base))
|
||||
if err != nil && base != "" {
|
||||
return base
|
||||
}
|
||||
modbase := base
|
||||
var agreement string
|
||||
for {
|
||||
fmt.Printf("---> The module %q already exists.\n---> Enter an alternate import name to use or ^C to cancel: ", modbase)
|
||||
fmt.Scanln(&base)
|
||||
fmt.Printf("-> Are you happy with %q?\n-> Type 'yes' to proceed: ", base)
|
||||
fmt.Scanln(&agreement)
|
||||
if strings.ToLower(agreement) == "yes" {
|
||||
break
|
||||
}
|
||||
}
|
||||
return base
|
||||
}
|
||||
|
||||
func Clone(url, modDir string) (string, error) {
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Unable to get current working directory\n")
|
||||
}
|
||||
defer func() { os.Chdir(pwd) }()
|
||||
err = os.Chdir(modDir)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
createDataDirs(modDir)
|
||||
err := os.Chdir(modDir)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Unable to navigate to module directory: %s \n", modDir)
|
||||
}
|
||||
} else if err != nil {
|
||||
return "", fmt.Errorf("Unable to navigate to module directory: %s\n", modDir)
|
||||
}
|
||||
|
||||
moduleName := ModName(url, modDir)
|
||||
fmt.Printf("Cloning %q...\n", moduleName)
|
||||
cmd := exec.Command("git", "clone", url, moduleName)
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(modDir, moduleName), nil
|
||||
}
|
||||
|
||||
func InstallModule(url string) {
|
||||
fmt.Println("NOTE: Submodules and module dependencies are not yet supported and will need to be acquired manually by a separate module installation")
|
||||
modDir := getModBaseDir()
|
||||
p, err := Clone(url, modDir)
|
||||
if err != nil || p == "" {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
return
|
||||
}
|
||||
_, err = os.Stat(filepath.Join(p, "main.slo"))
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
fmt.Fprintf(os.Stderr, "Invalid module, no 'main.slo' file. Removing from module folder\n")
|
||||
_ = os.RemoveAll(p)
|
||||
return
|
||||
}
|
||||
fmt.Println("Module successfully installed")
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
# Note On loading, modules, and preloading for the slope programming language
|
||||
|
||||
## Modules
|
||||
|
||||
### Loading a module
|
||||
|
||||
- (mod-load "git.rawtext.club/sloum/mymodule")
|
||||
- Only loads in define statements, will not run arbitrary code
|
||||
- chdirs into the repo folder to load so that relative imports work, using load should always be a relative reference within a module and should never point outside of the module folder, chdirs back to the execution folder after mod-load
|
||||
|
||||
### Creating a module: slope.mod
|
||||
|
||||
Fields are each a single line. The are a single word key followed by one or more ascii space characters followed by the value. Keys are case insensitive. Values are case sensitive.
|
||||
|
||||
- ENTRY ./my-module.slo
|
||||
- Should always be a relative path from the repo root
|
||||
- There can only be one entry. The last one read will be used. All others will be discarded
|
||||
- Additional files should be loaded using `(load "./myfile.slo")` or the like from within the entry file
|
||||
|
||||
- DEPENDENCY "git.rawtext.club/sloum/slope.git"
|
||||
- Will download the module to the user's $SLOPE_MODULES dir, or the default: `~/.config/share/slope/modules/`
|
||||
- Will read each of these modules' slope.mod and in turn download any of their dependencies that are not present on the system
|
||||
|
||||
- DESCRIPTION A description of the module
|
||||
|
||||
- SOURCE git.rawtext.club/sloum/slope
|
||||
- The git repo that this module can be found at
|
||||
- It will be a violation for this field to not match the import line and if this happens the module will not load
|
||||
|
||||
- NOTE This is random text that can be used to communicate info about the module as a human readable info tag for any general purpose the author may have
|
||||
|
||||
### Getting modules
|
||||
|
||||
Module loading will be supported by slope directly. However, the retrieval of modules is given over to a separate program yet to be named. This program will do the actual downloading, organizing, parsing, dependency management, etc. This splits things in a way that a Go style module system is used to some extent, but is managed by a tool more like `pip`.
|
||||
|
||||
No central code repository will be managed, but there is a possibility that a search functionality will be doable. The tool could accept something similar to an apt style ppa. Individuals could run websites that can be queried as a part of the search for modules. Folks could submit their modules to a site of their choice and then people can add that search provider if they feel like it. This lets users have flexibility and discoverability without needing to have a single point of failure or a huge thing for the slope author to maintain, though the slope author may opt to also support a search repo.
|
||||
|
Loading…
Reference in new issue