package main import ( "errors" "flag" "fmt" "os" "time" "github.com/fcuny/world/internal/version" "github.com/fcuny/world/pkg/flake/lock" ) const usage = `Usage: flake-info [flake.lock] Options: -v, --version Print version information -h, --help Print this message ` func main() { flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s\n", usage) } var ( flakeLockPath string versionFlag bool ) flag.StringVar(&flakeLockPath, "flake-lock", "flake.lock", "path to the flake lock file") flag.BoolVar(&versionFlag, "version", false, "Print version information") flag.BoolVar(&versionFlag, "v", false, "Print version information") flag.Parse() if versionFlag { information := version.VersionAndBuildInfo() fmt.Println(information) return } if _, err := os.Stat(flakeLockPath); err != nil { if errors.Is(err, os.ErrNotExist) { fmt.Fprintf(os.Stderr, "%s does not exists\n", flakeLockPath) } else { fmt.Fprintf(os.Stderr, "failed to check if %s exists: %v\n", flakeLockPath, err) } os.Exit(1) } lock, err := lock.New(flakeLockPath) if err != nil { fmt.Fprintf(os.Stderr, "failed to parse the lockfile for %s: %+v\n", flakeLockPath, err) os.Exit(1) } fmt.Printf("%s info:\n", flakeLockPath) fmt.Printf("version: %d\n", lock.Version) fmt.Printf("all nodes:\n") for nodeName, node := range lock.Nodes { date := time.Unix(node.Locked.LastModified, 0) unitTimeInRFC3339 := date.Format(time.RFC3339) fmt.Printf("- %s was updated on %s\n", nodeName, unitTimeInRFC3339) } }