From cdc8f1da9024b7bebf2a9ad54716cc911d296638 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Fri, 11 Oct 2024 04:05:15 +0000 Subject: refactor!: wiene -> yae It's far too easy to type wine. --- README.md | 12 ++-- flake.nix | 6 +- go.mod | 2 +- wiene.go | 190 -------------------------------------------------------------- yae.go | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 200 insertions(+), 200 deletions(-) delete mode 100644 wiene.go create mode 100644 yae.go diff --git a/README.md b/README.md index b8a9f7e..dfb9ba7 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# 🦖 Wiene +# ⛩️ Yae -Wiene is a simple dependency manager for use with Nix, similar to [niv](https://github.com/nmattia/niv/) +Yae is a simple dependency manager for use with Nix, similar to [niv](https://github.com/nmattia/niv/) and [`npins`](https://github.com/andir/npins/). I made it to solve my own problems, but I hope it can help you too. Try it out without installing anything permanently by running -`nix run github:Fuwn/wiene`! +`nix run github:Fuwn/yae`! ## Installation @@ -16,10 +16,10 @@ Follow the installation instructions at [Tsutsumi](https://github.com/Fuwn/tsuts ```text NAME: - wiene - Nix Dependency Manager + yae - Nix Dependency Manager USAGE: - wiene [global options] command [command options] + yae [global options] command [command options] DESCRIPTION: Nix Dependency Manager @@ -34,7 +34,7 @@ COMMANDS: help, h Shows a list of commands or help for one command GLOBAL OPTIONS: - --sources value Sources path (default: "./wiene.json") + --sources value Sources path (default: "./yae.json") --help, -h show help COPYRIGHT: diff --git a/flake.nix b/flake.nix index 64e2fc0..e66c393 100644 --- a/flake.nix +++ b/flake.nix @@ -37,7 +37,7 @@ system: let pkgs = import nixpkgs { inherit system; }; - name = "wiene"; + name = "yae"; meta = with pkgs.lib; { description = "Nix Dependency Manager"; @@ -48,7 +48,7 @@ platforms = platforms.linux; }; - wiene = + yae = pkgs.buildGo122Module.override { stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.clangStdenv; } rec { inherit meta; @@ -71,7 +71,7 @@ in { packages = { - default = wiene; + default = yae; ${name} = self.packages.${system}.default; }; diff --git a/go.mod b/go.mod index 733c26d..4dc332f 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/Fuwn/wiene +module github.com/Fuwn/yae go 1.22.7 diff --git a/wiene.go b/wiene.go deleted file mode 100644 index ec9f028..0000000 --- a/wiene.go +++ /dev/null @@ -1,190 +0,0 @@ -package main - -import ( - "fmt" - "os" - "os/exec" - "strings" - "time" - - "github.com/urfave/cli/v2" -) - -func main() { - sources := Sources{} - - (&cli.App{ - Name: "wiene", - Usage: "Nix Dependency Manager", - Description: "Nix Dependency Manager", - EnableBashCompletion: true, - Authors: []*cli.Author{ - { - Name: "Fuwn", - Email: "contact@fuwn.me", - }, - }, - Before: func(c *cli.Context) error { - return sources.Load(c.String("sources")) - }, - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "sources", - Value: "./wiene.json", - Usage: "Sources path", - }, - }, - Copyright: fmt.Sprintf("Copyright (c) 2024-%s Fuwn", fmt.Sprint(time.Now().Year())), - ExitErrHandler: func(c *cli.Context, err error) { - if err != nil { - fmt.Println(err) - } - }, - Suggest: true, - Commands: []*cli.Command{ - { - Name: "add", - Args: true, - ArgsUsage: " ", - Usage: "Add a source", - Flags: []cli.Flag{ - &cli.BoolFlag{ - Name: "unpack", - Usage: "Unpack the source into the Nix Store", - }, - }, - Action: func(c *cli.Context) error { - if c.Args().Len() != 2 { - return fmt.Errorf("invalid number of arguments") - } - - if sources.Exists(c.Args().Get(0)) { - return fmt.Errorf("source already exists") - } - - sha256, err := fetchSHA256(c.Args().Get(1), c.Bool("unpack")) - - if err != nil { - return err - } - - if err = sources.Add(c.Args().Get(0), Source{ - URI: c.Args().Get(1), - SHA256: sha256, - Unpack: c.Bool("unpack"), - }); err != nil { - return err - } - - return sources.Save(c.String("sources")) - }, - }, - { - Name: "drop", - Args: true, - Usage: "Drop a source", - Action: func(c *cli.Context) error { - if c.Args().Len() == 0 { - return fmt.Errorf("invalid number of arguments") - } - - if !sources.Exists(c.Args().Get(0)) { - return fmt.Errorf("source does not exist") - } - - sources.Drop(c.Args().Get(0)) - - return sources.Save(c.String("sources")) - }, - }, - { - Name: "update", - Args: true, - Usage: "Update one or all sources", - ArgsUsage: "[name]", - Flags: []cli.Flag{ - &cli.BoolFlag{ - Name: "unpack", - Usage: "Unpack the source into the Nix Store", - }, - }, - Action: func(c *cli.Context) error { - if c.Args().Len() == 0 { - for key, value := range sources { - sha256, err := fetchSHA256(value.URI, value.Unpack) - - if err != nil { - return err - } - - if sha256 != value.SHA256 { - sources[key] = Source{ - URI: value.URI, - SHA256: sha256, - Unpack: value.Unpack, - } - - fmt.Println("updated hash for", key) - } - - if err = sources.Save(c.String("sources")); err != nil { - return err - } - } - } else { - if !sources.Exists(c.Args().Get(0)) { - return fmt.Errorf("source does not exist") - } - - sha256, err := fetchSHA256(sources[c.Args().Get(0)].URI, c.Bool("unpack")) - - if err != nil { - return err - } - - sources[c.Args().Get(0)] = Source{ - URI: sources[c.Args().Get(0)].URI, - SHA256: sha256, - Unpack: c.Bool("unpack"), - } - - if err = sources.Save(c.String("sources")); err != nil { - return err - } - } - - return nil - }, - }, - }, - }).Run(os.Args) -} - -func fetchSHA256(uri string, unpack bool) (string, error) { - arguments := []string{"--type", "sha256", uri} - - if unpack { - arguments = append([]string{"--unpack"}, arguments...) - } - - output, err := commandOutput("nix-prefetch-url", arguments...) - - if err != nil { - return "", err - } - - lines := strings.Split(output, "\n") - - return strings.Trim(lines[len(lines)-2], "\n"), nil -} - -func commandOutput(name string, args ...string) (string, error) { - executable, err := exec.LookPath(name) - - cmd := exec.Command(executable, args...) - cmd.Stdin = os.Stdin - cmd.Stderr = os.Stderr - out, err := cmd.Output() - - return string(out), err -} diff --git a/yae.go b/yae.go new file mode 100644 index 0000000..baf1a9a --- /dev/null +++ b/yae.go @@ -0,0 +1,190 @@ +package main + +import ( + "fmt" + "os" + "os/exec" + "strings" + "time" + + "github.com/urfave/cli/v2" +) + +func main() { + sources := Sources{} + + (&cli.App{ + Name: "yae", + Usage: "Nix Dependency Manager", + Description: "Nix Dependency Manager", + EnableBashCompletion: true, + Authors: []*cli.Author{ + { + Name: "Fuwn", + Email: "contact@fuwn.me", + }, + }, + Before: func(c *cli.Context) error { + return sources.Load(c.String("sources")) + }, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "sources", + Value: "./yae.json", + Usage: "Sources path", + }, + }, + Copyright: fmt.Sprintf("Copyright (c) 2024-%s Fuwn", fmt.Sprint(time.Now().Year())), + ExitErrHandler: func(c *cli.Context, err error) { + if err != nil { + fmt.Println(err) + } + }, + Suggest: true, + Commands: []*cli.Command{ + { + Name: "add", + Args: true, + ArgsUsage: " ", + Usage: "Add a source", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "unpack", + Usage: "Unpack the source into the Nix Store", + }, + }, + Action: func(c *cli.Context) error { + if c.Args().Len() != 2 { + return fmt.Errorf("invalid number of arguments") + } + + if sources.Exists(c.Args().Get(0)) { + return fmt.Errorf("source already exists") + } + + sha256, err := fetchSHA256(c.Args().Get(1), c.Bool("unpack")) + + if err != nil { + return err + } + + if err = sources.Add(c.Args().Get(0), Source{ + URI: c.Args().Get(1), + SHA256: sha256, + Unpack: c.Bool("unpack"), + }); err != nil { + return err + } + + return sources.Save(c.String("sources")) + }, + }, + { + Name: "drop", + Args: true, + Usage: "Drop a source", + Action: func(c *cli.Context) error { + if c.Args().Len() == 0 { + return fmt.Errorf("invalid number of arguments") + } + + if !sources.Exists(c.Args().Get(0)) { + return fmt.Errorf("source does not exist") + } + + sources.Drop(c.Args().Get(0)) + + return sources.Save(c.String("sources")) + }, + }, + { + Name: "update", + Args: true, + Usage: "Update one or all sources", + ArgsUsage: "[name]", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "unpack", + Usage: "Unpack the source into the Nix Store", + }, + }, + Action: func(c *cli.Context) error { + if c.Args().Len() == 0 { + for key, value := range sources { + sha256, err := fetchSHA256(value.URI, value.Unpack) + + if err != nil { + return err + } + + if sha256 != value.SHA256 { + sources[key] = Source{ + URI: value.URI, + SHA256: sha256, + Unpack: value.Unpack, + } + + fmt.Println("updated hash for", key) + } + + if err = sources.Save(c.String("sources")); err != nil { + return err + } + } + } else { + if !sources.Exists(c.Args().Get(0)) { + return fmt.Errorf("source does not exist") + } + + sha256, err := fetchSHA256(sources[c.Args().Get(0)].URI, c.Bool("unpack")) + + if err != nil { + return err + } + + sources[c.Args().Get(0)] = Source{ + URI: sources[c.Args().Get(0)].URI, + SHA256: sha256, + Unpack: c.Bool("unpack"), + } + + if err = sources.Save(c.String("sources")); err != nil { + return err + } + } + + return nil + }, + }, + }, + }).Run(os.Args) +} + +func fetchSHA256(uri string, unpack bool) (string, error) { + arguments := []string{"--type", "sha256", uri} + + if unpack { + arguments = append([]string{"--unpack"}, arguments...) + } + + output, err := commandOutput("nix-prefetch-url", arguments...) + + if err != nil { + return "", err + } + + lines := strings.Split(output, "\n") + + return strings.Trim(lines[len(lines)-2], "\n"), nil +} + +func commandOutput(name string, args ...string) (string, error) { + executable, err := exec.LookPath(name) + + cmd := exec.Command(executable, args...) + cmd.Stdin = os.Stdin + cmd.Stderr = os.Stderr + out, err := cmd.Output() + + return string(out), err +} -- cgit v1.2.3