about summary refs log tree commit diff
path: root/cmd/flake-info/main.go
blob: d41f3210a8e6e4ebd67fbe8147a9c2cd31aadf5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main

import (
	"errors"
	"flag"
	"fmt"
	"os"
	"time"

	"github.com/fcuny/world/pkg/flake/lock"
)

func main() {
	var flakeLockPath string

	flag.StringVar(&flakeLockPath, "flake-lock", "flake.lock", "path to the flake lock file")

	flag.Parse()

	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)
	}
}