aboutsummaryrefslogtreecommitdiff
path: root/cmd/flake-info/main.go
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2024-01-21 13:11:33 -0800
committerFranck Cuny <franck@fcuny.net>2024-01-21 13:12:44 -0800
commitb5ee47e701259575f22745f920fb4e7013eb0412 (patch)
tree870b9800907a01187d1b0407a18b646c00c90199 /cmd/flake-info/main.go
parentinstall some go related programs (diff)
downloadinfra-b5ee47e701259575f22745f920fb4e7013eb0412.tar.gz
initial version of the flake-info command
A tool to display information about a flake. For now we shows all the inputs and when they were updated last.
Diffstat (limited to 'cmd/flake-info/main.go')
-rw-r--r--cmd/flake-info/main.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/cmd/flake-info/main.go b/cmd/flake-info/main.go
new file mode 100644
index 0000000..d41f321
--- /dev/null
+++ b/cmd/flake-info/main.go
@@ -0,0 +1,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)
+ }
+}