BLAH
Jes Olson jolson@digitalocean.com
Wed, 09 Feb 2022 21:50:43 -0600
5 files changed,
53 insertions(+),
19 deletions(-)
M
config.go
→
config/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.go
→
main.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) + } }