nix-amer/main.go

57 lines
1010 B
Go
Raw Normal View History

2018-11-08 13:09:32 +00:00
package main
import (
"fmt"
"git.xdrm.io/go/nix-amer/internal/buildfile"
"git.xdrm.io/go/nix-amer/internal/clifmt"
"os"
"time"
)
2018-11-08 13:09:32 +00:00
func main() {
start := time.Now()
// Manage arguments
ctx, bf, dryRun, err := GetArgs()
if err != nil {
2018-11-10 11:58:08 +00:00
fmt.Printf("%s\n", err)
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
instructions, err := buildfile.NewReader(ctx, bfreader)
if err != nil {
fmt.Printf("%s%s\n", bf, err)
return
}
clifmt.Align("build file")
fmt.Printf("%s\n", clifmt.Color(32, "valid"))
// stop here if dry run
if dryRun {
return
}
// 3. Execute
fmt.Printf("------\n")
err = instructions.Execute()
if err != nil {
fmt.Printf("%s\n", clifmt.Warn(err.Error()))
return
}
fmt.Printf("------\n")
clifmt.Align("finished in")
fmt.Printf("%ss\n", clifmt.Color(32, fmt.Sprintf("%.2f", time.Now().Sub(start).Seconds())))
2018-11-08 13:09:32 +00:00
}