Compare commits

...

2 Commits

Author SHA1 Message Date
jolheiser 1528f971fa
fix: use Path to be consistent on Windows
ci/woodpecker/push/goreleaser Pipeline was successful Details
Signed-off-by: jolheiser <john.olheiser@gmail.com>
2023-01-18 12:59:54 -06:00
jolheiser 3854458d5d
fix: use home dir instead of OS-specific dirs
Signed-off-by: jolheiser <john.olheiser@gmail.com>
2023-01-18 12:27:34 -06:00
3 changed files with 25 additions and 17 deletions

View File

@ -12,7 +12,6 @@ import (
"go.jolheiser.com/eget/forge" "go.jolheiser.com/eget/forge"
"github.com/adrg/xdg"
"github.com/mholt/archiver/v3" "github.com/mholt/archiver/v3"
) )
@ -120,5 +119,9 @@ func moveDir(src, dest string) error {
} }
func Path(name string) string { 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)
} }

View File

@ -19,6 +19,8 @@ func main() {
fmt.Fprintln(fs.Output(), "eget <package>") fmt.Fprintln(fs.Output(), "eget <package>")
fs.PrintDefaults() fs.PrintDefaults()
} }
versionFlag := fs.Bool("version", false, "Show version and exit")
fs.BoolVar(versionFlag, "v", *versionFlag, "--version")
updateFlag := fs.Bool("update", false, "Update package") updateFlag := fs.Bool("update", false, "Update package")
fs.BoolVar(updateFlag, "u", *updateFlag, "--update") fs.BoolVar(updateFlag, "u", *updateFlag, "--update")
deleteFlag := flag.Bool("delete", false, "Delete package") deleteFlag := flag.Bool("delete", false, "Delete package")
@ -29,6 +31,11 @@ func main() {
return return
} }
if *versionFlag {
fmt.Printf("eget %s\n", Version)
return
}
if *syncFlag { if *syncFlag {
if err := sync(); err != nil { if err := sync(); err != nil {
panic(err) panic(err)

View File

@ -6,11 +6,10 @@ import (
"fmt" "fmt"
"io/fs" "io/fs"
"os" "os"
"path/filepath"
"strings" "strings"
"go.jolheiser.com/eget/disk" "go.jolheiser.com/eget/disk"
"github.com/adrg/xdg"
) )
type Meta struct { type Meta struct {
@ -47,10 +46,7 @@ func Read() (Meta, error) {
m := Meta{ m := Meta{
Packages: make(map[string]Package), Packages: make(map[string]Package),
} }
fp, err := metaPath() fp := metaPath()
if err != nil {
return m, fmt.Errorf("could not get meta file: %w", err)
}
fi, err := os.Open(fp) fi, err := os.Open(fp)
if err != nil { if err != nil {
if errors.Is(err, fs.ErrNotExist) { 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) return fmt.Errorf("could not find package to remove for %q", name)
} }
func metaPath() (string, error) { func metaPath() string {
return xdg.ConfigFile("eget/packages.json") home, err := os.UserHomeDir()
if err != nil {
home = "."
}
return filepath.Join(home, ".eget", "packages.json")
} }
func save(m Meta) error { func save(m Meta) error {
fp, err := metaPath() fp := metaPath()
if err != nil {
return fmt.Errorf("could not get meta path: %w", err)
}
fi, err := os.Create(fp) fi, err := os.Create(fp)
if err != nil { if err != nil {
return fmt.Errorf("could not create meta file: %w", err) return fmt.Errorf("could not create meta file: %w", err)
@ -117,7 +114,7 @@ func (m Meta) writeShellEnv(shell string) error {
var tmpl string var tmpl string
switch shell { switch shell {
case "nu": case "nu":
tmpl = "let-env PATH = ($env.PATH | append '%s')\n" tmpl = "let-env Path = ($env.Path | append %q)\n"
case "sh": case "sh":
tmpl = "PATH=$PATH:%s\n" tmpl = "PATH=$PATH:%s\n"
case "ps1": case "ps1":
@ -125,10 +122,11 @@ func (m Meta) writeShellEnv(shell string) error {
default: default:
return errors.New("shell not recognized") return errors.New("shell not recognized")
} }
fp, err := xdg.DataFile("eget/eget." + shell) home, err := os.UserHomeDir()
if err != nil { if err != nil {
return err home = "."
} }
fp := filepath.Join(home, ".eget", "eget."+shell)
fi, err := os.Create(fp) fi, err := os.Create(fp)
if err != nil { if err != nil {
return err return err