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