diff --git a/.gitignore b/.gitignore
index 095658d..dbe0109 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
dyn-pkg
+.idea/
+rsh
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 6aa7a51..80f341e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
install:
- go build .
+ v .
mv dyn /usr/bin/dyn
push:
git add .
diff --git a/cmd/cli/main.go b/cmd/cli/main.go
deleted file mode 100644
index 29865b2..0000000
--- a/cmd/cli/main.go
+++ /dev/null
@@ -1,113 +0,0 @@
-package cli
-
-import (
- "fmt"
- "os"
- "os/exec"
- "path/filepath"
- "strings"
-
- "github.com/go-git/go-git/v5"
- "github.com/restartfu/dyn/internal/logger"
- "github.com/savioxavier/termlink"
-)
-
-type CLI struct {
- Version string
- ForceSudo bool
- PkgDir string
-}
-
-func (c CLI) Execute() {
- if arg, ok := arg(1); ok && arg == "version" {
- fmt.Println(c.Version)
- return
- }
-
- _, su := os.LookupEnv("SUDO_COMMAND")
- if !su && c.ForceSudo {
- logger.Fatalf("dyn must be run as a super user.\n")
- }
-
- act, ok := arg(1)
- if !ok || !isAnyString(act, "update", "install", "remove", "fetch") {
- logger.Fatalf("valid actions: update|install|remove|fetch.\n")
- }
-
- pkgArgN := 2
- if act == "fetch" {
- c.fetch()
- act, ok = arg(pkgArgN)
- if !ok || !isAnyString(act, "update", "install", "remove") {
- return
- }
- pkgArgN = 3
- }
-
- pkg, ok := arg(pkgArgN)
- if !ok {
- if act != "update" {
- logger.Fatalf("please specify the package you wish to %s.\n", act)
- }
- act = "update"
- pkg = "dyn"
- }
-
- c.executePackage(pkg, act)
- logger.Dynf("if you wish to contribute, make sure to check out %s\n",
- termlink.ColorLink("our github page", "https://github.com/restartfu/dyn", "yellow"))
- logger.Dynf("done %s package %s.\n", verb(act), pkg)
-}
-
-func (c CLI) executePackage(pkg string, act string) {
- targetPkgPath := filepath.Join(c.PkgDir, pkg)
- if _, err := os.Stat(targetPkgPath); os.IsNotExist(err) {
- logger.Fatalf("no package found with the name %s, maybe run 'dyn fetch', and try again?\n", pkg)
- }
-
- scriptPath := filepath.Join(targetPkgPath, "DYNPKG")
- if _, err := os.Stat(scriptPath); os.IsNotExist(err) {
- logger.Fatalf("no DYNPKG file found for package %s, maybe run 'dyn fetch', and try again?\n", pkg)
- }
- scriptBuf, err := os.ReadFile(scriptPath)
- if err != nil {
- logger.Fatalf("could not read DYNPKG file for package %s", pkg)
- }
-
- script := []string{
- string(scriptBuf),
- act,
- `if [ -n "$maintainers" ]; then
- credits=$(echo "special thanks to ( $maintainers ) for maintaining this package")
- echo $credits;
- fi`,
- }
- tmpScriptPath := filepath.Join(os.TempDir(), "dyn-pkg", pkg, "script.sh")
- tmpDir := filepath.Dir(tmpScriptPath)
- os.RemoveAll(tmpDir)
- os.MkdirAll(tmpDir, os.ModePerm)
- os.WriteFile(tmpScriptPath, []byte(strings.Join(script, "\n")), os.ModePerm)
-
- logger.Dynf("%s package %s.\n", verb(act), pkg)
- cmd := exec.Command("sh", "-c", tmpScriptPath)
- cmd.Stdout = logger.InfoOut
- cmd.Stderr = os.Stderr
- cmd.Run()
-
- os.RemoveAll(tmpDir)
-}
-
-func (c CLI) fetch() {
- logger.Dynf("fetching dyn-pkg git repository.\n")
-
- os.RemoveAll(c.PkgDir)
- _, err := git.PlainClone(c.PkgDir, false, &git.CloneOptions{
- Depth: 1,
- URL: "https://github.com/RestartFU/dyn-pkg",
- Progress: logger.InfoOut,
- })
-
- if err != nil {
- logger.Fatalf("error fetching dyn package repository: %s.\n", err)
- }
-}
diff --git a/cmd/cli/util.go b/cmd/cli/util.go
deleted file mode 100644
index f342f4f..0000000
--- a/cmd/cli/util.go
+++ /dev/null
@@ -1,36 +0,0 @@
-package cli
-
-import (
- "os"
-)
-
-func verb(s string) string {
- switch s {
- case "install":
- return "installing"
- case "update":
- return "updating"
- case "remove":
- return "removing"
- case "fetch":
- return "fetching"
- }
- panic("should never happend")
-}
-
-func arg(n int) (string, bool) {
- args := os.Args
- if len(args) <= n {
- return "", false
- }
- return args[n], true
-}
-
-func isAnyString(s string, a ...string) bool {
- for _, str := range a {
- if str == s {
- return true
- }
- }
- return false
-}
diff --git a/go.mod b/go.mod
deleted file mode 100644
index 3b77899..0000000
--- a/go.mod
+++ /dev/null
@@ -1,40 +0,0 @@
-module github.com/restartfu/dyn
-
-go 1.23.0
-
-require (
- github.com/go-git/go-git v4.7.0+incompatible
- github.com/sandertv/gophertunnel v1.40.2-0.20240901120213-8954c4aef268
-)
-
-require (
- dario.cat/mergo v1.0.0 // indirect
- github.com/Microsoft/go-winio v0.6.1 // indirect
- github.com/ProtonMail/go-crypto v1.0.0 // indirect
- github.com/cloudflare/circl v1.3.7 // indirect
- github.com/cyphar/filepath-securejoin v0.2.4 // indirect
- github.com/emirpasic/gods v1.18.1 // indirect
- github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
- github.com/go-git/go-billy/v5 v5.5.0 // indirect
- github.com/go-git/go-git/v5 v5.12.0 // indirect
- github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
- github.com/google/go-cmp v0.6.0 // indirect
- github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
- github.com/kevinburke/ssh_config v1.2.0 // indirect
- github.com/mitchellh/go-homedir v1.1.0 // indirect
- github.com/pjbgf/sha1cd v0.3.0 // indirect
- github.com/savioxavier/termlink v1.4.1 // indirect
- github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
- github.com/skeema/knownhosts v1.2.2 // indirect
- github.com/src-d/gcfg v1.4.0 // indirect
- github.com/stretchr/testify v1.9.0 // indirect
- github.com/xanzy/ssh-agent v0.3.3 // indirect
- golang.org/x/crypto v0.24.0 // indirect
- golang.org/x/mod v0.12.0 // indirect
- golang.org/x/net v0.26.0 // indirect
- golang.org/x/sys v0.21.0 // indirect
- golang.org/x/tools v0.13.0 // indirect
- gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
- gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
- gopkg.in/warnings.v0 v0.1.2 // indirect
-)
diff --git a/go.sum b/go.sum
deleted file mode 100644
index c59befd..0000000
--- a/go.sum
+++ /dev/null
@@ -1,185 +0,0 @@
-dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
-dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
-github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
-github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
-github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
-github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78=
-github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
-github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
-github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
-github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
-github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
-github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
-github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
-github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
-github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
-github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
-github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
-github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
-github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
-github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
-github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
-github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
-github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
-github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
-github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
-github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
-github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
-github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
-github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
-github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
-github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
-github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
-github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU=
-github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow=
-github.com/go-git/go-git v4.7.0+incompatible h1:+W9rgGY4DOKKdX2x6HxSR7HNeTxqiKrOvKnuittYVdA=
-github.com/go-git/go-git v4.7.0+incompatible/go.mod h1:6+421e08gnZWn30y26Vchf7efgYLe4dl5OQbBSUXShE=
-github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys=
-github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY=
-github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
-github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
-github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
-github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
-github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
-github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
-github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
-github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
-github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
-github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
-github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
-github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
-github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
-github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
-github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
-github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
-github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
-github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
-github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
-github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
-github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
-github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
-github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
-github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
-github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
-github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
-github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
-github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/sandertv/gophertunnel v1.40.2-0.20240901120213-8954c4aef268 h1:nYZg5PdYELahZ6nj/guHMT1s+asQ9k1YbvjsECfYlVo=
-github.com/sandertv/gophertunnel v1.40.2-0.20240901120213-8954c4aef268/go.mod h1:uSaX7RbVaCcxsGAx2vyZnkT0M6kZFGCdAqLn0+wuKyY=
-github.com/savioxavier/termlink v1.4.1 h1:pFcd+XH8iQjL+2mB4buCDUo+CMt5kKsr8jGG+VLfYAg=
-github.com/savioxavier/termlink v1.4.1/go.mod h1:5T5ePUlWbxCHIwyF8/Ez1qufOoGM89RCg9NvG+3G3gc=
-github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
-github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
-github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
-github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
-github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
-github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
-github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A=
-github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
-github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
-github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
-github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
-github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
-github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
-github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
-github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
-github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
-github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
-github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
-github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
-github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
-github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
-golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
-golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
-golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
-golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
-golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
-golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
-golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
-golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
-golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
-golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
-golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
-golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
-golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
-golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
-golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
-golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
-golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
-golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
-golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
-golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
-golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
-golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
-golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
-golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
-golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
-golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
-golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
-golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
-golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
-golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
-golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA=
-golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
-golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
-golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
-golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
-golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
-golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
-golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
-golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
-golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
-golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
-golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
-golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
-golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
-golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
-golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
-golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
-gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
-gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg=
-gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98=
-gopkg.in/src-d/go-git-fixtures.v3 v3.5.0 h1:ivZFOIltbce2Mo8IjzUHAFoq/IylO9WHhNOAJK+LsJg=
-gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g=
-gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE=
-gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8=
-gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
-gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
-gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/internal/.keep b/internal/.keep
deleted file mode 100644
index e69de29..0000000
diff --git a/internal/logger/logger.go b/internal/logger/logger.go
deleted file mode 100644
index 9ed539a..0000000
--- a/internal/logger/logger.go
+++ /dev/null
@@ -1,54 +0,0 @@
-package logger
-
-import (
- "fmt"
- "os"
-
- "github.com/sandertv/gophertunnel/minecraft/text"
-)
-
-func Debugf(str string, args ...any) {
- printf("DEBU", str, args...)
-}
-
-func Fatalf(str string, args ...any) {
- printf("FATA", str, args...)
- os.Exit(0)
-}
-
-func Fatal(str string) {
- print("FATA", str)
- os.Exit(0)
-}
-
-func Errorf(str string, args ...any) {
- printf("ERRO", str, args...)
-}
-
-func Error(str string) {
- print("ERRO", str)
-}
-
-func Infof(str string, args ...any) {
- printf("INFO", str, args...)
-}
-
-func Info(str string) {
- print("INFO", str)
-}
-
-func Dynf(str string, args ...any) {
- printf("DYN ", str, args...)
-}
-
-func printf(prefix string, str string, args ...any) {
- fmt.Print(text.ANSI(text.Colourf(prefix+"| ")) + fmt.Sprintf(str, args...))
-}
-
-func Color(str string) string {
- return text.ANSI(text.Colourf(str))
-}
-
-func print(prefix string, str string) {
- fmt.Print(text.ANSI(text.Colourf(prefix+"| ")) + str)
-}
diff --git a/internal/logger/writer.go b/internal/logger/writer.go
deleted file mode 100644
index 028daa1..0000000
--- a/internal/logger/writer.go
+++ /dev/null
@@ -1,16 +0,0 @@
-package logger
-
-var (
- FatalOut = Writer{log: Fatal}
- ErrorOut = Writer{log: Error}
- InfoOut = Writer{log: Info}
-)
-
-type Writer struct {
- log func(str string)
-}
-
-func (w Writer) Write(p []byte) (n int, err error) {
- w.log(string(p))
- return len(p), err
-}
diff --git a/main.go b/main.go
deleted file mode 100644
index 4b297fa..0000000
--- a/main.go
+++ /dev/null
@@ -1,23 +0,0 @@
-package main
-
-import (
- "flag"
-
- "github.com/restartfu/dyn/cmd/cli"
- "github.com/restartfu/dyn/internal/logger"
-)
-
-var version = logger.Color("v0.1.4")
-
-func main() {
- nosudo := flag.Bool("nosudo", false, "")
- pkgDir := flag.String("pkgdir", "/usr/local/dyn-pkg", "")
- flag.Parse()
-
- c := cli.CLI{
- Version: version,
- ForceSudo: !*nosudo,
- PkgDir: *pkgDir,
- }
- c.Execute()
-}
diff --git a/main.v b/main.v
new file mode 100644
index 0000000..516950e
--- /dev/null
+++ b/main.v
@@ -0,0 +1,8 @@
+module main
+
+import rsh
+
+fn main() {
+ res := rsh.parse_script("./dyn-pkg/go/DYNPKG")
+ res.run("install")
+}
diff --git a/rsh/function.v b/rsh/function.v
new file mode 100644
index 0000000..4e00dda
--- /dev/null
+++ b/rsh/function.v
@@ -0,0 +1,51 @@
+module rsh
+
+import os
+import net.http
+import compress.gzip
+import compress.szip
+
+struct Function {
+mut:
+ actions []fn ()
+}
+
+fn delete(path string) {
+ sh("rm -rf ${path}")
+}
+
+fn sh(s string) {
+ println(s)
+ os.system(s)
+}
+
+fn (p Parser) internal(line int, cursor int, s string, res &Script) {
+ fnc := res.functions[s] or {
+ println("${p.filename}: ${line}:${cursor}: no function with the name ${s} found")
+ exit(0)
+ }
+ for act in fnc.actions {
+ act()
+ }
+}
+
+fn link(input string, output string) {
+ sh("ln -s $(realpath ${input}) $output")
+}
+
+fn unzip(input string, output string) {
+ szip.extract_zip_to_dir(input, output) or {
+ exit(0)
+ }
+}
+
+fn move(input string, output string) {
+ sh("mv ${input} ${output}")
+}
+
+fn (p Parser) download(line int, url string, output string) {
+ http.download_file_with_progress(url, output) or {
+ println('${p.filename}: ${line}:0 could not download file from ${url} to ${output}')
+ exit(0)
+ }
+}
\ No newline at end of file
diff --git a/rsh/logger.v b/rsh/logger.v
new file mode 100644
index 0000000..17e71e7
--- /dev/null
+++ b/rsh/logger.v
@@ -0,0 +1,2 @@
+module rsh
+
diff --git a/rsh/parser.v b/rsh/parser.v
new file mode 100644
index 0000000..d2ea7ae
--- /dev/null
+++ b/rsh/parser.v
@@ -0,0 +1,123 @@
+module rsh
+
+import os
+
+struct Parser {
+ filename string
+mut:
+ tokenizer Tokenizer
+ result Script
+}
+
+fn (mut p Parser) expect(kind TokenKind) Token {
+ mut tok := p.tokenizer.token()
+ if tok.kind != kind {
+ println("${p.filename}: ${p.tokenizer.line}:${p.tokenizer.cursor}: expected token kind '${kind.identifier}' but got '${tok.kind.identifier}' instead")
+ exit(0)
+ }
+ if tok.kind == tok_string {
+ for id, v in p.result.variables {
+ tok.text = tok.text.replace("$" + "{" + id + "}", v)
+ }
+ }
+ return tok
+}
+
+fn (mut p Parser) parse_function() {
+ identifier := p.expect(tok_identifier).text
+ p.result.functions[identifier] = Function{}
+
+ p.expect(tok_left_bracket)
+
+ mut tok := p.tokenizer.token()
+ for tok.kind != tok_right_bracket {
+ line := tok.line
+ match tok.text {
+ "unzip" {
+ from := p.expect(tok_string).text
+ p.expect(tok_to)
+ to := p.expect(tok_string).text
+
+ p.result.functions[identifier].actions << fn [from, to] () { unzip(from, to) }
+ }
+ "download" {
+ url := p.expect(tok_string).text
+ p.expect(tok_to)
+ output := p.expect(tok_string).text
+
+ p.result.functions[identifier].actions << fn [p, url, output, line] () { p.download(line, url, output) }
+ }
+ "sh" {
+ s := p.expect(tok_string).text
+ p.result.functions[identifier].actions << fn[s] () { sh(s) }
+ }
+ "link" {
+ from := p.expect(tok_string).text
+ p.expect(tok_to)
+ to := p.expect(tok_string).text
+
+ p.result.functions[identifier].actions << fn [from, to] () { link(from, to) }
+ }
+ "internal" {
+ res := &p.result
+ func := p.expect(tok_identifier)
+ p.result.functions[identifier].actions << fn[func, res, p, line] () { p.internal(line, func.cursor,func.text, res) }
+ }
+ "delete" {
+ s := p.expect(tok_string).text
+ p.result.functions[identifier].actions << fn[s] () { delete(s) }
+ }
+ "move" {
+ from := p.expect(tok_string).text
+ p.expect(tok_to)
+ to := p.expect(tok_string).text
+
+ p.result.functions[identifier].actions << fn [from, to] () { move(from, to) }
+ }
+ else {}
+ }
+ tok = p.tokenizer.token()
+ }
+}
+
+fn (mut p Parser) parse_require() {
+ value := p.expect(tok_identifier).text
+ p.result.requires << value
+}
+
+fn (mut p Parser) parse_variable() {
+ identifier := p.expect(tok_identifier).text
+ p.expect(tok_equals)
+ value := p.expect(tok_string).text
+ p.result.variables[identifier] = value
+}
+
+pub fn parse_script(filename string) Script {
+ data := os.read_file(filename) or {
+ panic(err)
+ }
+
+ mut parser := &Parser{
+ filename: os.file_name(filename)
+ tokenizer: Tokenizer{data: data}
+ }
+
+ mut tok := parser.tokenizer.token()
+ for tok.kind != tok_eof {
+ match tok.kind {
+ tok_variable {
+ parser.parse_variable()
+ }
+ tok_function {
+ parser.parse_function()
+ }
+ tok_require {
+ parser.parse_require()
+ }
+ else {}
+ }
+ tok = parser.tokenizer.token()
+ }
+
+ return parser.result
+}
\ No newline at end of file
diff --git a/rsh/script.v b/rsh/script.v
new file mode 100644
index 0000000..fff4d24
--- /dev/null
+++ b/rsh/script.v
@@ -0,0 +1,31 @@
+module rsh
+
+import os
+
+struct Script {
+ mut:
+ functions map[string]Function
+ requires []string
+ variables map[string]string
+}
+
+pub fn (s Script) variable(identifier string) string {
+ return s.variables[identifier]
+}
+
+pub fn (s Script) run(function string) {
+ for r in s.requires {
+ os.find_abs_path_of_executable(r) or {
+ println("please install '${r}'")
+ exit(0)
+ }
+ }
+
+ func := s.functions[function] or {
+ println("no function found with the name ${function}")
+ exit(0)
+ }
+ for act in func.actions {
+ act()
+ }
+}
\ No newline at end of file
diff --git a/rsh/tokenizer.v b/rsh/tokenizer.v
new file mode 100644
index 0000000..e75af3e
--- /dev/null
+++ b/rsh/tokenizer.v
@@ -0,0 +1,198 @@
+module rsh
+
+import os
+
+struct Position {
+mut:
+ offset int
+ line int = 1
+ cursor int
+}
+
+struct Token {
+ Position
+mut:
+ kind TokenKind
+ text string
+}
+
+struct TokenKind {
+ identifier string
+}
+
+struct Tokenizer {
+ Position
+mut:
+ r rune
+ data string
+}
+
+
+fn (mut t Tokenizer) next() rune {
+ t.offset++
+ t.cursor++
+
+ dat := t.data[t.offset-1..]
+ if t.offset > t.data.len || dat.len <= 0 {
+ return 0
+ }
+
+ r := dat[0]
+ if r == `\n` {
+ t.line++
+ t.cursor=0
+ }
+ return r
+}
+
+fn (mut t Tokenizer) previous() rune {
+ t.offset--
+ t.cursor--
+
+ dat := t.data[t.offset..]
+ if t.offset > t.data.len || dat.len <= 0 {
+ return 0
+ }
+
+ r := dat[0]
+ if r == `\n` {
+ t.line--
+ }
+ return r
+}
+
+fn (mut t Tokenizer) skip_white_space() {
+ t.r = t.next()
+ for is_any(t.r, `\n`, ` `, `\t`, `\r`, `\f`) {
+ t.r = t.next()
+ }
+}
+
+fn (mut t Tokenizer) token() Token {
+ t.skip_white_space()
+
+ mut tok := Token{}
+ tok.Position = t.Position
+ tok.kind = tok_invalid
+
+ match t.r {
+ 0 {
+ tok.kind = tok_eof
+ return tok
+ }
+ `$` {
+ t.r = t.next()
+ if t.r == `(` {
+ tok.kind = tok_string
+ for t.offset < t.data.len {
+ t.r = t.next()
+ if t.r == `)` {
+ break
+ }
+ tok.text += t.r.str()
+ }
+ tok.text = os.raw_execute(tok.text).output.trim_space()
+ }
+ }
+ `#` {
+ tok.kind = tok_comment
+
+ for t.offset < t.data.len {
+ t.r = t.next()
+ if t.r == `\n` {
+ break
+ }
+ tok.text += t.r.str()
+ }
+ }
+ `=` {
+ tok.kind = tok_equals
+ tok.text = "="
+ }
+ `{` {
+ tok.kind = tok_left_bracket
+ tok.text = "{"
+ }
+ `}` {
+ tok.kind = tok_right_bracket
+ tok.text = "}"
+ }
+ `"` {
+ tok.kind = tok_string
+ for t.offset < t.data.len {
+ t.r = t.next()
+ match t.r {
+ `$` {
+ t.r = t.next()
+ if t.r == `(` {
+ mut shcmd := ""
+ for t.offset < t.data.len {
+ if t.r == `)` {
+ tok.text += os.raw_execute(shcmd[1..]).output.trim_space()
+ t.r = t.next()
+ break
+ }
+ shcmd += t.r.str()
+ t.r = t.next()
+ }
+ } else {
+ tok.text += "$"
+ }
+ }
+ `"` {
+ break
+ }
+ else {}
+ }
+ tok.text += t.r.str()
+ }
+ }
+ else {
+ tok.kind = tok_identifier
+ for t.offset < t.data.len {
+ if is_any(t.r,`\n`, ` `, `\t`, `\r`, `\f`) {
+ break
+ }
+
+ tok.text += t.r.str()
+ t.r = t.next()
+
+ mut should_break := true
+
+ match tok.text{
+ "to" {
+ tok.kind = tok_to
+ }
+ "variable"{
+ tok.kind = tok_variable
+ }
+ "function" {
+ tok.kind = tok_function
+ }
+ "require" {
+ tok.kind = tok_require
+ }
+ else {
+ should_break = false
+ }
+ }
+
+ if should_break {
+ break
+ }
+ }
+ }
+ }
+
+ println("${tok.line}:${tok.cursor} -> '${tok.text}' len[${tok.text.len}] kind[${tok.kind.identifier}]")
+ return tok
+}
+
+fn is_any(r rune, runes ...rune) bool {
+ for v in runes {
+ if r == v {
+ return true
+ }
+ }
+ return false
+}
\ No newline at end of file
diff --git a/rsh/tokens.v b/rsh/tokens.v
new file mode 100644
index 0000000..37290c0
--- /dev/null
+++ b/rsh/tokens.v
@@ -0,0 +1,17 @@
+module rsh
+
+const (
+ tok_eof = TokenKind{identifier: "EOF"}
+ tok_invalid = TokenKind{identifier: "invalid"}
+ tok_string = TokenKind{identifier: "string"}
+ tok_variable = TokenKind{identifier: "variable"}
+ tok_to = TokenKind{identifier: "to"}
+ tok_function = TokenKind{identifier: "function"}
+ tok_comment = TokenKind{identifier: "comment"}
+ tok_identifier = TokenKind{identifier: "identifier"}
+ tok_equals = TokenKind{identifier: "equals"}
+
+ tok_left_bracket = TokenKind{identifier: "left bracket"}
+ tok_right_bracket = TokenKind{identifier: "right bracket"}
+ tok_require = TokenKind{identifier: "require"}
+)
diff --git a/cmd/.keep b/v.mod
similarity index 100%
rename from cmd/.keep
rename to v.mod