2018-11-08 13:09:32 +00:00
|
|
|
package main
|
|
|
|
|
2018-11-10 11:37:31 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2018-11-10 11:48:45 +00:00
|
|
|
"git.xdrm.io/go/nix-amer/internal/buildfile"
|
|
|
|
"git.xdrm.io/go/nix-amer/internal/clifmt"
|
2018-11-10 11:37:31 +00:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2018-11-08 13:09:32 +00:00
|
|
|
func main() {
|
2018-11-10 11:37:31 +00:00
|
|
|
|
|
|
|
// Manage arguments
|
2018-11-10 11:45:58 +00:00
|
|
|
ctx, bf, dryRun, err := GetArgs()
|
2018-11-10 11:37:31 +00:00
|
|
|
if err != nil {
|
2018-11-10 11:58:08 +00:00
|
|
|
fmt.Printf("%s\n", err)
|
2018-11-10 11:37:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1. get buildfile reader
|
|
|
|
bfreader, err := os.Open(bf)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("cannot open buildfile | %s\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer bfreader.Close()
|
|
|
|
|
|
|
|
// 2. parse buildfile
|
2018-11-10 11:45:58 +00:00
|
|
|
instructions, err := buildfile.NewReader(ctx, bfreader)
|
2018-11-10 11:37:31 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("%s%s\n", bf, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
clifmt.Align("build file")
|
2018-11-10 11:45:58 +00:00
|
|
|
fmt.Printf("%s\n", clifmt.Color(32, "valid"))
|
|
|
|
|
|
|
|
// stop here if dry run
|
|
|
|
if dryRun {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3. Execute
|
|
|
|
clifmt.Align("execution")
|
|
|
|
fmt.Printf("start\n")
|
|
|
|
err = instructions.Execute()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("%s\n", clifmt.Warn(err.Error()))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
clifmt.Align("execution")
|
|
|
|
fmt.Printf("%s\n", clifmt.Color(32, "finished"))
|
2018-11-10 11:37:31 +00:00
|
|
|
|
2018-11-08 13:09:32 +00:00
|
|
|
}
|