From 3854458d5d11908f368e5b8dee083f8057ea5413 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Wed, 18 Jan 2023 12:27:34 -0600 Subject: [PATCH] fix: use home dir instead of OS-specific dirs Signed-off-by: jolheiser --- disk/disk.go | 7 +++++-- main.go | 7 +++++++ meta/meta.go | 26 ++++++++++++-------------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/disk/disk.go b/disk/disk.go index 1a38d66..be5b0d8 100644 --- a/disk/disk.go +++ b/disk/disk.go @@ -12,7 +12,6 @@ import ( "go.jolheiser.com/eget/forge" - "github.com/adrg/xdg" "github.com/mholt/archiver/v3" ) @@ -120,5 +119,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) } diff --git a/main.go b/main.go index c8e2dde..c873020 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,8 @@ func main() { fmt.Fprintln(fs.Output(), "eget ") 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") @@ -29,6 +31,11 @@ func main() { return } + if *versionFlag { + fmt.Printf("eget %s\n", Version) + return + } + if *syncFlag { if err := sync(); err != nil { panic(err) diff --git a/meta/meta.go b/meta/meta.go index c74f560..121a1d4 100644 --- a/meta/meta.go +++ b/meta/meta.go @@ -6,11 +6,10 @@ import ( "fmt" "io/fs" "os" + "path/filepath" "strings" "go.jolheiser.com/eget/disk" - - "github.com/adrg/xdg" ) type Meta struct { @@ -47,10 +46,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 +76,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) @@ -125,10 +122,11 @@ func (m Meta) writeShellEnv(shell string) error { 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