about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--cmd/flakeinfo/main.go22
-rw-r--r--pkg/flake/lock/main.go16
2 files changed, 31 insertions, 7 deletions
diff --git a/cmd/flakeinfo/main.go b/cmd/flakeinfo/main.go
index 8c1960c..23a5169 100644
--- a/cmd/flakeinfo/main.go
+++ b/cmd/flakeinfo/main.go
@@ -5,7 +5,7 @@ import (
 	"flag"
 	"fmt"
 	"os"
-	"time"
+	"text/template"
 
 	"github.com/fcuny/world/internal/version"
 	"github.com/fcuny/world/pkg/flake/lock"
@@ -19,6 +19,11 @@ Options:
     -h, --help        Print this message
 `
 
+const tmplInput = ` • repository: {{ .Locked.Repository }}
+ • updated on: {{ .Locked.LastModifiedRFC3339 }}
+
+`
+
 func main() {
 	flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s\n", usage) }
 
@@ -54,12 +59,15 @@ func main() {
 		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)
+		tmpl, err := template.New("tmpl").Parse(tmplInput)
+		if err != nil {
+			panic(err)
+		}
+		fmt.Printf("%s\n", nodeName)
+		err = tmpl.Execute(os.Stdout, node)
+		if err != nil {
+			panic(err)
+		}
 	}
 }
diff --git a/pkg/flake/lock/main.go b/pkg/flake/lock/main.go
index 0fa21f4..7edf61f 100644
--- a/pkg/flake/lock/main.go
+++ b/pkg/flake/lock/main.go
@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"os"
+	"time"
 )
 
 type FlakeLock struct {
@@ -91,3 +92,18 @@ func New(flakeLockPath string) (*FlakeLock, error) {
 
 	return &flakeLock, nil
 }
+
+func (l repoLocked) LastModifiedRFC3339() string {
+	date := time.Unix(l.LastModified, 0)
+	unitTimeInRFC3339 := date.Format(time.RFC3339)
+	return unitTimeInRFC3339
+}
+
+func (l repoLocked) Repository() string {
+	switch l.Type {
+	case "github":
+		return fmt.Sprintf("https://github.com/%s/%s", l.Owner, l.Repo)
+	default:
+		return fmt.Sprintf("%s/%s", l.Repo, l.Owner)
+	}
+}