Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
jolheiser | 123857ac73 | |
jolheiser | e8303793b2 | |
jolheiser | ad08d24312 | |
jolheiser | d8f45eb0b9 | |
jolheiser | 4b65d05dcc | |
jolheiser | 3bccb54f54 | |
jolheiser | dd84c45c71 | |
jolheiser | 2ec8d755c9 | |
jolheiser | ce1e1a1f1d | |
jolheiser | ca426d5fd2 | |
jolheiser | 1528f971fa | |
jolheiser | 3854458d5d | |
jolheiser | eed5f4e358 |
|
@ -4,12 +4,12 @@ builds:
|
|||
goos:
|
||||
- linux
|
||||
- windows
|
||||
- darwin
|
||||
goarch:
|
||||
- amd64
|
||||
ldflags:
|
||||
- "-s -w -X main.Version={{.Version}}"
|
||||
archives:
|
||||
- replacements:
|
||||
386: i386
|
||||
amd64: x86_64
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
**E**asily **get** a project from a release on GitHub/Gitea.
|
||||
|
||||
This project is based on work I've done with [webman](https://github.com/candrewlee14/webman) and another project also called [eget](https://github.com/zyedidia/eget).
|
||||
This project lies somewhere in between them in terms of feature-set.
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
|
11
disk/disk.go
11
disk/disk.go
|
@ -12,8 +12,8 @@ import (
|
|||
|
||||
"go.jolheiser.com/eget/forge"
|
||||
|
||||
"github.com/adrg/xdg"
|
||||
"github.com/mholt/archiver/v3"
|
||||
"github.com/schollz/progressbar/v3"
|
||||
)
|
||||
|
||||
func Install(name string, asset forge.Asset) error {
|
||||
|
@ -35,7 +35,8 @@ func Install(name string, asset forge.Asset) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err := io.Copy(fi, resp.Body); err != nil {
|
||||
bar := progressbar.DefaultBytes(resp.ContentLength, "downloading")
|
||||
if _, err := io.Copy(io.MultiWriter(fi, bar), resp.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := fi.Close(); err != nil {
|
||||
|
@ -120,5 +121,9 @@ func moveDir(src, dest string) error {
|
|||
}
|
||||
|
||||
func Path(name string) string {
|
||||
return filepath.Join(xdg.DataHome, "eget", name)
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
home = "."
|
||||
}
|
||||
return filepath.Join(home, ".eget", name)
|
||||
}
|
||||
|
|
|
@ -4,15 +4,17 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
amd64Re = regexp.MustCompile(`amd64|x86_64|64-bit|[^mhv]64`)
|
||||
linuxRe = regexp.MustCompile(`linux`)
|
||||
windowsRe = regexp.MustCompile(`windows|\Awin`)
|
||||
amd64Re = regexp.MustCompile(`amd64|x86_64|64-bit|[^mhv]64`)
|
||||
linuxRe = regexp.MustCompile(`(?i)linux`)
|
||||
windowsRe = regexp.MustCompile(`(?i)windows|\Awin`)
|
||||
installerRe = regexp.MustCompile(`\.deb|\.msi`)
|
||||
)
|
||||
|
||||
type Release struct {
|
||||
|
@ -46,7 +48,7 @@ func splitURI(uri string) (string, []string, error) {
|
|||
return u.String(), paths, nil
|
||||
}
|
||||
|
||||
func TagRelease(f Forger, tag string) (Asset, error) {
|
||||
func TagRelease(f Forger, tag, override string) (Asset, error) {
|
||||
var asset Asset
|
||||
|
||||
var re *regexp.Regexp
|
||||
|
@ -64,8 +66,25 @@ func TagRelease(f Forger, tag string) (Asset, error) {
|
|||
return asset, fmt.Errorf("could not get %q release: %w", tag, err)
|
||||
}
|
||||
|
||||
overrideName := os.Expand(override, func(s string) string {
|
||||
switch strings.ToLower(s) {
|
||||
case "os", "goos":
|
||||
return runtime.GOOS
|
||||
case "arch", "goarch":
|
||||
return runtime.GOARCH
|
||||
case "version":
|
||||
return release.Name
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
})
|
||||
|
||||
for _, a := range release.Assets {
|
||||
if amd64Re.MatchString(a.Name) && re.MatchString(a.Name) {
|
||||
match := strings.EqualFold(a.Name, overrideName)
|
||||
if overrideName == "" {
|
||||
match = amd64Re.MatchString(a.Name) && re.MatchString(a.Name) && !installerRe.MatchString(a.Name)
|
||||
}
|
||||
if match {
|
||||
fmt.Printf("found %q\n", a.Name)
|
||||
asset = a
|
||||
break
|
||||
|
@ -80,36 +99,12 @@ func TagRelease(f Forger, tag string) (Asset, error) {
|
|||
return asset, nil
|
||||
}
|
||||
|
||||
func LatestRelease(f Forger) (Asset, error) {
|
||||
func LatestRelease(f Forger, override string) (Asset, error) {
|
||||
var asset Asset
|
||||
|
||||
var re *regexp.Regexp
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
re = linuxRe
|
||||
case "windows":
|
||||
re = windowsRe
|
||||
default:
|
||||
return asset, fmt.Errorf("%q is not a supported OS", runtime.GOOS)
|
||||
}
|
||||
|
||||
release, err := f.latestRelease()
|
||||
if err != nil {
|
||||
return asset, fmt.Errorf("could not get latest release: %w", err)
|
||||
}
|
||||
|
||||
for _, a := range release.Assets {
|
||||
if amd64Re.MatchString(a.Name) && re.MatchString(a.Name) {
|
||||
fmt.Printf("found %q\n", a.Name)
|
||||
asset = a
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if asset.Name == "" {
|
||||
return asset, errors.New("no release found for this OS")
|
||||
}
|
||||
|
||||
asset.Version = release.Name
|
||||
return asset, nil
|
||||
return TagRelease(f, release.Name, override)
|
||||
}
|
||||
|
|
8
go.mod
8
go.mod
|
@ -3,8 +3,8 @@ module go.jolheiser.com/eget
|
|||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/adrg/xdg v0.4.0
|
||||
github.com/mholt/archiver/v3 v3.5.1
|
||||
github.com/schollz/progressbar/v3 v3.13.0
|
||||
)
|
||||
|
||||
require (
|
||||
|
@ -13,9 +13,13 @@ require (
|
|||
github.com/golang/snappy v0.0.2 // indirect
|
||||
github.com/klauspost/compress v1.11.4 // indirect
|
||||
github.com/klauspost/pgzip v1.2.5 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||
github.com/nwaples/rardecode v1.1.0 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.2 // indirect
|
||||
github.com/rivo/uniseg v0.4.3 // indirect
|
||||
github.com/ulikunitz/xz v0.5.9 // indirect
|
||||
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
|
||||
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 // indirect
|
||||
golang.org/x/sys v0.4.0 // indirect
|
||||
golang.org/x/term v0.4.0 // indirect
|
||||
)
|
||||
|
|
30
go.sum
30
go.sum
|
@ -1,41 +1,51 @@
|
|||
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
|
||||
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
|
||||
github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
|
||||
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
|
||||
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 h1:iFaUwBSo5Svw6L7HYpRu/0lE3e0BaElwnNO1qkNQxBY=
|
||||
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj60/X5sZFNxpG4HBPDHVqxNm4DfnCKgrbZOT+s=
|
||||
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
|
||||
github.com/golang/snappy v0.0.2 h1:aeE13tS0IiQgFjYdoL8qN3K1N2bXXtI6Vi51/y7BpMw=
|
||||
github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
|
||||
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||
github.com/klauspost/compress v1.11.4 h1:kz40R/YWls3iqT9zX9AHN3WoVsrAWVyui5sxuLqiXqU=
|
||||
github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
||||
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
||||
github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE=
|
||||
github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
|
||||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
|
||||
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mholt/archiver/v3 v3.5.1 h1:rDjOBX9JSF5BvoJGvjqK479aL70qh9DIpZCl+k7Clwo=
|
||||
github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4=
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
|
||||
github.com/nwaples/rardecode v1.1.0 h1:vSxaY8vQhOcVr4mm5e8XllHWTiM4JF507A0Katqw7MQ=
|
||||
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
|
||||
github.com/pierrec/lz4/v4 v4.1.2 h1:qvY3YFXRQE/XB8MlLzJH7mSzBs74eA2gg52YTk6jUPM=
|
||||
github.com/pierrec/lz4/v4 v4.1.2/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
|
||||
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/schollz/progressbar/v3 v3.13.0 h1:9TeeWRcjW2qd05I8Kf9knPkW4vLM/hYoa6z9ABvxje8=
|
||||
github.com/schollz/progressbar/v3 v3.13.0/go.mod h1:ZBYnSuLAX2LU8P8UiKN/KgF2DY58AJC8yfVYLPC8Ly4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||
github.com/ulikunitz/xz v0.5.9 h1:RsKRIA2MO8x56wkkcd3LbtcE/uMszhb6DpRf+3uwa3I=
|
||||
github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
|
||||
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
|
||||
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 h1:2B5p2L5IfGiD7+b9BOoRMC6DgObAVZV+Fsp050NqXik=
|
||||
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
|
||||
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.4.0 h1:O7UWfv5+A2qiuulQk30kVinPoMtoIPeVaKLEgLpVkvg=
|
||||
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
38
main.go
38
main.go
|
@ -14,21 +14,35 @@ import (
|
|||
var Version = "develop"
|
||||
|
||||
func main() {
|
||||
base := "github.com/"
|
||||
if b, ok := os.LookupEnv("EGET_BASE"); ok {
|
||||
base = strings.TrimSuffix(b, "/") + "/"
|
||||
}
|
||||
|
||||
fs := flag.NewFlagSet("eget", flag.ExitOnError)
|
||||
fs.Usage = func() {
|
||||
fmt.Fprintln(fs.Output(), "eget <package>")
|
||||
fs.PrintDefaults()
|
||||
}
|
||||
versionFlag := fs.Bool("version", false, "Show version and exit")
|
||||
fs.BoolVar(versionFlag, "v", *versionFlag, "--version")
|
||||
updateFlag := fs.Bool("update", false, "Update package")
|
||||
fs.BoolVar(updateFlag, "u", *updateFlag, "--update")
|
||||
deleteFlag := flag.Bool("delete", false, "Delete package")
|
||||
fs.BoolVar(deleteFlag, "d", *deleteFlag, "--delete")
|
||||
syncFlag := fs.Bool("sync", false, "Sync packages")
|
||||
overrideFlag := fs.String("override", "", "Override asset to look for: $OS, $ARCH, and $VERSION are available as templates")
|
||||
fs.StringVar(overrideFlag, "o", *overrideFlag, "--override")
|
||||
if err := fs.Parse(os.Args[1:]); err != nil {
|
||||
fs.Usage()
|
||||
return
|
||||
}
|
||||
|
||||
if *versionFlag {
|
||||
fmt.Printf("eget %s\n", Version)
|
||||
return
|
||||
}
|
||||
|
||||
if *syncFlag {
|
||||
if err := sync(); err != nil {
|
||||
panic(err)
|
||||
|
@ -49,10 +63,22 @@ func main() {
|
|||
}
|
||||
uri := fs.Arg(0)
|
||||
|
||||
if *updateFlag && strings.Index(uri, "/") == -1 {
|
||||
if pkg, ok := m.Packages[uri]; ok {
|
||||
uri = pkg.Repo
|
||||
if strings.Index(uri, "/") == -1 {
|
||||
if !(*updateFlag || *deleteFlag) {
|
||||
fmt.Printf("%q was not a URI and --update/--delete was not passed\n", uri)
|
||||
return
|
||||
}
|
||||
|
||||
pkg, ok := m.Packages[uri]
|
||||
if !ok {
|
||||
fmt.Printf("%q was not a URI and didn't match an installed package\n", uri)
|
||||
return
|
||||
}
|
||||
uri = pkg.Repo
|
||||
}
|
||||
|
||||
if strings.Count(uri, "/") == 1 {
|
||||
uri = base + uri
|
||||
}
|
||||
|
||||
f, err = forge.NewGitea(uri)
|
||||
|
@ -75,7 +101,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
asset, err := forge.LatestRelease(f)
|
||||
asset, err := forge.LatestRelease(f, *overrideFlag)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -94,7 +120,7 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
if err := meta.Upsert(name, uri, asset.Version); err != nil {
|
||||
if err := meta.Upsert(name, uri, asset.Version, asset.Name); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
@ -130,7 +156,7 @@ func sync() error {
|
|||
return err
|
||||
}
|
||||
|
||||
asset, err := forge.TagRelease(f, pkg.Version)
|
||||
asset, err := forge.TagRelease(f, pkg.Version, pkg.Asset)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
40
meta/meta.go
40
meta/meta.go
|
@ -6,11 +6,11 @@ import (
|
|||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"go.jolheiser.com/eget/disk"
|
||||
|
||||
"github.com/adrg/xdg"
|
||||
)
|
||||
|
||||
type Meta struct {
|
||||
|
@ -20,9 +20,10 @@ type Meta struct {
|
|||
type Package struct {
|
||||
Repo string `json:"repo"`
|
||||
Version string `json:"version"`
|
||||
Asset string `json:"asset"`
|
||||
}
|
||||
|
||||
func Upsert(name, repo, version string) error {
|
||||
func Upsert(name, repo, version, asset string) error {
|
||||
m, err := Read()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -32,6 +33,7 @@ func Upsert(name, repo, version string) error {
|
|||
m.Packages[n] = Package{
|
||||
Repo: repo,
|
||||
Version: version,
|
||||
Asset: asset,
|
||||
}
|
||||
return save(m)
|
||||
}
|
||||
|
@ -39,6 +41,7 @@ func Upsert(name, repo, version string) error {
|
|||
m.Packages[name] = Package{
|
||||
Repo: repo,
|
||||
Version: version,
|
||||
Asset: asset,
|
||||
}
|
||||
return save(m)
|
||||
}
|
||||
|
@ -47,10 +50,7 @@ func Read() (Meta, error) {
|
|||
m := Meta{
|
||||
Packages: make(map[string]Package),
|
||||
}
|
||||
fp, err := metaPath()
|
||||
if err != nil {
|
||||
return m, fmt.Errorf("could not get meta file: %w", err)
|
||||
}
|
||||
fp := metaPath()
|
||||
fi, err := os.Open(fp)
|
||||
if err != nil {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
|
@ -80,15 +80,16 @@ func Remove(name string) error {
|
|||
return fmt.Errorf("could not find package to remove for %q", name)
|
||||
}
|
||||
|
||||
func metaPath() (string, error) {
|
||||
return xdg.ConfigFile("eget/packages.json")
|
||||
func metaPath() string {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
home = "."
|
||||
}
|
||||
return filepath.Join(home, ".eget", "packages.json")
|
||||
}
|
||||
|
||||
func save(m Meta) error {
|
||||
fp, err := metaPath()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get meta path: %w", err)
|
||||
}
|
||||
fp := metaPath()
|
||||
fi, err := os.Create(fp)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create meta file: %w", err)
|
||||
|
@ -117,18 +118,23 @@ func (m Meta) writeShellEnv(shell string) error {
|
|||
var tmpl string
|
||||
switch shell {
|
||||
case "nu":
|
||||
tmpl = "let-env PATH = ($env.PATH | append '%s')\n"
|
||||
path := "PATH"
|
||||
if runtime.GOOS == "windows" {
|
||||
path = "Path"
|
||||
}
|
||||
tmpl = fmt.Sprintf("let-env %[1]s = ($env.%[1]s | append %%q)\n", path)
|
||||
case "sh":
|
||||
tmpl = "PATH=$PATH:%s\n"
|
||||
tmpl = "PATH=$PATH:%q\n"
|
||||
case "ps1":
|
||||
tmpl = `$env:Path = "$env:Path;%s"` + "\n"
|
||||
default:
|
||||
return errors.New("shell not recognized")
|
||||
}
|
||||
fp, err := xdg.DataFile("eget/eget." + shell)
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return err
|
||||
home = "."
|
||||
}
|
||||
fp := filepath.Join(home, ".eget", "eget."+shell)
|
||||
fi, err := os.Create(fp)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Reference in New Issue