63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"git.xdrm.io/go/nix-amer/internal/buildfile"
|
|
"git.xdrm.io/go/nix-amer/internal/clifmt"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
|
|
start := time.Now()
|
|
|
|
// Manage arguments
|
|
ctx, bf, dryRun, err := GetArgs()
|
|
if err != nil {
|
|
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 {
|
|
if _, ok := err.(buildfile.LineError); ok {
|
|
fmt.Printf("line error\n")
|
|
fmt.Printf("%s%s\n", bf, err.Error())
|
|
} else {
|
|
fmt.Printf("%s\n", clifmt.Warn(err.Error()))
|
|
}
|
|
return
|
|
}
|
|
|
|
clifmt.Align("build file")
|
|
fmt.Printf("%s\n", clifmt.Color(32, "valid"))
|
|
|
|
// stop here if dry run
|
|
|
|
// 3. Execute
|
|
fmt.Printf("------\n")
|
|
err = instructions.Execute(dryRun)
|
|
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())))
|
|
|
|
if dryRun {
|
|
fmt.Printf("\n%s %s\n", clifmt.Info("updated configurations are inside"), clifmt.Color(32, "/tmp/dry-run"))
|
|
}
|
|
|
|
}
|