separar runner de cli

This commit is contained in:
Cat /dev/Nulo 2023-01-22 10:14:48 -03:00
parent 7fe4b8c08e
commit 17560621e0
9 changed files with 34 additions and 31 deletions

26
cli.go Normal file
View file

@ -0,0 +1,26 @@
package main
import (
"encoding/json"
"log"
"os"
"gitea.nulo.in/Nulo/repro-run/runner"
)
func main() {
config, err := readConfig()
must(err)
must(runner.Run(config, "rootfs/", "cache/"))
}
func must(err error, where ...string) {
if err != nil {
log.Fatal(err, where)
}
}
func readConfig() (config runner.Config, err error) {
err = json.NewDecoder(os.Stdin).Decode(&config)
return
}

View file

@ -1,16 +0,0 @@
package main
import (
"encoding/json"
"os"
)
type Config struct {
Command string
Cache []string
}
func readConfig() (config Config, err error) {
err = json.NewDecoder(os.Stdin).Decode(&config)
return
}

6
runner/config.go Normal file
View file

@ -0,0 +1,6 @@
package runner
type Config struct {
Command string
Cache []string
}

View file

@ -1,4 +1,4 @@
package main package runner
import ( import (
"embed" "embed"
@ -14,14 +14,7 @@ import (
//go:embed alpine/keys //go:embed alpine/keys
var alpineKeys embed.FS var alpineKeys embed.FS
func main() { func Run(config Config, rootfs string, cache string) (err error) {
config, err := readConfig()
must(err)
must(run(config, "rootfs/", "cache/"))
}
func run(config Config, rootfs string, cache string) (err error) {
if err = os.RemoveAll("rootfs/"); err != nil { if err = os.RemoveAll("rootfs/"); err != nil {
return return
} }
@ -124,9 +117,3 @@ https://dl-cdn.alpinelinux.org/alpine/v3.17/community`), 0600); err != nil {
return return
} }
func must(err error, where ...string) {
if err != nil {
log.Fatal(err, where)
}
}