small pixel drawing of a pufferfish lilp

BLAH
Jes Olson jolson@digitalocean.com
Wed, 09 Feb 2022 21:50:43 -0600
commit

95e430b31cc9a900759dcc61ec89fb6f3868906f

parent

79350fdb3e314f98027dcf353ee03b526f1764c8

5 files changed, 53 insertions(+), 19 deletions(-)

jump to
M READMEREADME

@@ -1,6 +1,8 @@

lil process ------------ +~the shittiest process manager in the world~ + lilp watches git repositories for changes, clones them when they arrive, and then runs arbitrary commands for you after the cloning is complete.
M config.goconfig/config.go

@@ -1,4 +1,4 @@

-package main +package config import ( "log"

@@ -17,7 +17,7 @@ Ref string

RunCmds []string } -func shittilyParseConfig(file string) Config { +func ShittilyParseConfig(file string) Config { var conf Config data, err := os.ReadFile(file) if err != nil {

@@ -28,7 +28,11 @@ configPieces := strings.Split(string(data), "\n")

var process Process for _, chunk := range configPieces { if chunk == "" { - conf.Processes = append(conf.Processes, process) + // write the process hunk if lolol + // lmao wat this is awful + if process.Name != "" { + conf.Processes = append(conf.Processes, process) + } continue } parts := strings.Split(chunk, "\"")
D contrib/example-config

@@ -1,11 +0,0 @@

-process "lil-shell-example" - clone "https://git.j3s.sh/whatever" - ref "main" - run "echo hi mom && sleep 1" - run "whatever" - -process "docker-example" - clone "https://git.j3s.sh/dockerstuff" - ref "master" - run "docker build ." - run "docker run ."
A example-config

@@ -0,0 +1,5 @@

+process "lil-shell-example" + run "echo hi mom" + run "sleep 2" + run "sleep 4" + run "sleep 3"
M main.gomain.go

@@ -1,15 +1,49 @@

package main import ( - "errors" "log" + "os/exec" + "strings" + + "git.j3s.sh/lilp/config" ) -func startProc(p Process) error { - return errors.New("what") +func startProc(p config.Process) error { + log.Printf("proc: %+v", p) + return nil +} + +func cloneRepo(repo string, dest string) { + if repo == "" { + return + } + + // git clone $repo $dest +} + +func runProcEternally(commands []string) { + // run eternally, lul + for { + for _, c := range commands { + fullcmd := strings.Split(c, " ") + cmd := exec.Command(fullcmd[0], fullcmd[1:]...) + err := cmd.Run() + if err != nil { + log.Fatal(err) + } + } + } } func main() { - lilpConfig := shittilyParseConfig("./contrib/example-config") - log.Printf("config: %+v", lilpConfig) + lilpConfig := config.ShittilyParseConfig("./example-config") + if len(lilpConfig.Processes) == 0 { + log.Fatal("no processes found in config. exiting cowardly.") + } + for _, proc := range lilpConfig.Processes { + log.Printf("starting process %s", proc) + cloneRepo(proc.Clone, proc.Name) + // TODO: implement watching or whatever + go runProcEternally(proc.RunCmds) + } }