Compare commits
No commits in common. "1528f971fa8bf989dba8b5351b881ae63b89b5f0" and "eed5f4e358be9646a64f3f74ef6782676703ea40" have entirely different histories.
1528f971fa
...
eed5f4e358
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
"go.jolheiser.com/eget/forge"
|
||||
|
||||
"github.com/adrg/xdg"
|
||||
"github.com/mholt/archiver/v3"
|
||||
)
|
||||
|
||||
|
@ -119,9 +120,5 @@ func moveDir(src, dest string) error {
|
|||
}
|
||||
|
||||
func Path(name string) string {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
home = "."
|
||||
}
|
||||
return filepath.Join(home, ".eget", name)
|
||||
return filepath.Join(xdg.DataHome, "eget", name)
|
||||
}
|
||||
|
|
7
main.go
7
main.go
|
@ -19,8 +19,6 @@ func main() {
|
|||
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")
|
||||
|
@ -31,11 +29,6 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
if *versionFlag {
|
||||
fmt.Printf("eget %s\n", Version)
|
||||
return
|
||||
}
|
||||
|
||||
if *syncFlag {
|
||||
if err := sync(); err != nil {
|
||||
panic(err)
|
||||
|
|
28
meta/meta.go
28
meta/meta.go
|
@ -6,10 +6,11 @@ import (
|
|||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"go.jolheiser.com/eget/disk"
|
||||
|
||||
"github.com/adrg/xdg"
|
||||
)
|
||||
|
||||
type Meta struct {
|
||||
|
@ -46,7 +47,10 @@ func Read() (Meta, error) {
|
|||
m := Meta{
|
||||
Packages: make(map[string]Package),
|
||||
}
|
||||
fp := metaPath()
|
||||
fp, err := metaPath()
|
||||
if err != nil {
|
||||
return m, fmt.Errorf("could not get meta file: %w", err)
|
||||
}
|
||||
fi, err := os.Open(fp)
|
||||
if err != nil {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
|
@ -76,16 +80,15 @@ func Remove(name string) error {
|
|||
return fmt.Errorf("could not find package to remove for %q", name)
|
||||
}
|
||||
|
||||
func metaPath() string {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
home = "."
|
||||
}
|
||||
return filepath.Join(home, ".eget", "packages.json")
|
||||
func metaPath() (string, error) {
|
||||
return xdg.ConfigFile("eget/packages.json")
|
||||
}
|
||||
|
||||
func save(m Meta) error {
|
||||
fp := metaPath()
|
||||
fp, err := metaPath()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get meta path: %w", err)
|
||||
}
|
||||
fi, err := os.Create(fp)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create meta file: %w", err)
|
||||
|
@ -114,7 +117,7 @@ func (m Meta) writeShellEnv(shell string) error {
|
|||
var tmpl string
|
||||
switch shell {
|
||||
case "nu":
|
||||
tmpl = "let-env Path = ($env.Path | append %q)\n"
|
||||
tmpl = "let-env PATH = ($env.PATH | append '%s')\n"
|
||||
case "sh":
|
||||
tmpl = "PATH=$PATH:%s\n"
|
||||
case "ps1":
|
||||
|
@ -122,11 +125,10 @@ func (m Meta) writeShellEnv(shell string) error {
|
|||
default:
|
||||
return errors.New("shell not recognized")
|
||||
}
|
||||
home, err := os.UserHomeDir()
|
||||
fp, err := xdg.DataFile("eget/eget." + shell)
|
||||
if err != nil {
|
||||
home = "."
|
||||
return err
|
||||
}
|
||||
fp := filepath.Join(home, ".eget", "eget."+shell)
|
||||
fi, err := os.Create(fp)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Reference in New Issue