diff options
author | Franck Cuny <franck@fcuny.net> | 2024-05-06 19:28:58 -0700 |
---|---|---|
committer | Franck Cuny <franck@fcuny.net> | 2024-05-06 19:29:57 -0700 |
commit | fdeb06f2c9e0bbb8e30de30c54e393cf19d3a3f8 (patch) | |
tree | f5972443b7adcdb6b030ff4391b001856a465d12 | |
parent | move robloxenv to hashienv under `src' (diff) | |
download | world-fdeb06f2c9e0bbb8e30de30c54e393cf19d3a3f8.tar.gz |
messing with stuff
-rw-r--r-- | cmd/flakeinfo/main.go | 73 | ||||
-rw-r--r-- | go.mod | 3 | ||||
-rw-r--r-- | go.sum | 0 | ||||
-rw-r--r-- | internal/git/main.go | 22 | ||||
-rw-r--r-- | internal/terminal/link.go | 13 | ||||
-rw-r--r-- | internal/version/main.go | 12 | ||||
-rw-r--r-- | pkg/flake/lock/main.go | 109 |
7 files changed, 0 insertions, 232 deletions
diff --git a/cmd/flakeinfo/main.go b/cmd/flakeinfo/main.go deleted file mode 100644 index 23a5169..0000000 --- a/cmd/flakeinfo/main.go +++ /dev/null @@ -1,73 +0,0 @@ -package main - -import ( - "errors" - "flag" - "fmt" - "os" - "text/template" - - "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 -` - -const tmplInput = ` • repository: {{ .Locked.Repository }} - • updated on: {{ .Locked.LastModifiedRFC3339 }} - -` - -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) - } - - for nodeName, node := range lock.Nodes { - 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/go.mod b/go.mod deleted file mode 100644 index c28fd3c..0000000 --- a/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/fcuny/world - -go 1.21.4 diff --git a/go.sum b/go.sum deleted file mode 100644 index e69de29..0000000 --- a/go.sum +++ /dev/null diff --git a/internal/git/main.go b/internal/git/main.go deleted file mode 100644 index 67e7d4d..0000000 --- a/internal/git/main.go +++ /dev/null @@ -1,22 +0,0 @@ -package git - -import ( - "fmt" - "os/exec" - "strings" -) - -func Root() (string, error) { - cmd := exec.Command("git", "rev-parse", "--show-toplevel") - output, err := cmd.Output() - if err != nil { - return "", fmt.Errorf("failed to get git repository: %s", err) - } - - // The output includes the full path to the repository. To get just the name, - // we can split the path by "/" and take the last part. - pathParts := strings.Split(strings.TrimSpace(string(output)), "/") - repoName := pathParts[len(pathParts)-1] - - return repoName, nil -} diff --git a/internal/terminal/link.go b/internal/terminal/link.go deleted file mode 100644 index a50b199..0000000 --- a/internal/terminal/link.go +++ /dev/null @@ -1,13 +0,0 @@ -package terminal - -import "fmt" - -// Link returns a formatted string that represents a hyperlink. -// The hyperlink is created using the escape sequence for terminal emulators. -// The text parameter represents the visible text of the hyperlink, -// and the url parameter represents the URL that the hyperlink points to. -// For more information on the escape sequence, refer to: -// https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#the-escape-sequence -func Link(text string, url string) string { - return fmt.Sprintf("\x1b]8;;%s\x07%s\x1b]8;;\x07\u001b[0m", url, text) -} diff --git a/internal/version/main.go b/internal/version/main.go deleted file mode 100644 index d8a745f..0000000 --- a/internal/version/main.go +++ /dev/null @@ -1,12 +0,0 @@ -package version - -import "fmt" - -var Version, BuildDate string - -func VersionAndBuildInfo() string { - if Version != "" { - return fmt.Sprintf("version: %s, build on: %s", Version, BuildDate) - } - return "(unknown)" -} diff --git a/pkg/flake/lock/main.go b/pkg/flake/lock/main.go deleted file mode 100644 index 7edf61f..0000000 --- a/pkg/flake/lock/main.go +++ /dev/null @@ -1,109 +0,0 @@ -package lock - -import ( - "encoding/json" - "fmt" - "os" - "time" -) - -type FlakeLock struct { - // Version of the lock file - Version int - // Root is the root node for the flake, containing all the inputs - Root RootNode - // Nodes represent all the inputs node for a flake - Nodes map[string]Node -} - -type Node struct { - // Flake indicate whether the input is a flake - Flake bool `json:"flake"` - // Locked represent the locked attribute of the input - Locked repoLocked `json:"locked"` - // Original represent the user supplied attributes for the input - Original repoOriginal `json:"original"` -} - -type repoLocked struct { - // LastModified represent the timestamp of when the input was updated last - LastModified int64 `json:"lastModified"` - // NarHash is the NAR hash for the input - NarHash string `json:"narHash"` - // Owner of the repository - Owner string `json:"owner"` - // Repository of the input - Repo string `json:"repo"` - // Revision of the input - Rev string `json:"rev"` - // Type of input - Type string `json:"type"` -} - -type repoOriginal struct { - Owner string `json:"owner"` - Ref string `json:"ref"` - Repo string `json:"repo"` - Type string `json:"type"` -} - -// RootNode is a mapping of input -type RootNode struct { - // Inputs contains the mapping of input - Inputs map[string]string `json:"inputs"` -} - -// New return a representation of a flake lock -func New(flakeLockPath string) (*FlakeLock, error) { - content, err := os.ReadFile(flakeLockPath) - if err != nil { - return nil, fmt.Errorf("failed to read %s: %v", flakeLockPath, err) - } - - var lock struct { - Version int `json:"version"` - Root string `json:"root"` - Nodes map[string]json.RawMessage `json:"nodes"` - } - - if err := json.Unmarshal(content, &lock); err != nil { - return nil, fmt.Errorf("failed to parse %s: %v", flakeLockPath, err) - } - - var flakeLock FlakeLock - flakeLock.Version = lock.Version - flakeLock.Nodes = map[string]Node{} - - for nodeName, node := range lock.Nodes { - if nodeName != lock.Root { - var n Node - if err := json.Unmarshal(node, &n); err != nil { - return nil, fmt.Errorf("failed to read node %s: %v", nodeName, err) - } - flakeLock.Nodes[nodeName] = n - } else { - var r RootNode - if err := json.Unmarshal(node, &r); err != nil { - return nil, fmt.Errorf("failed to read the root node: %v", err) - } - flakeLock.Root = r - } - } - - 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) - } -} |