From fd64435af3eccf382ea9c1cc88123915fa5b7682 Mon Sep 17 00:00:00 2001 From: David Ashby Date: Mon, 19 May 2025 10:08:04 -0400 Subject: [PATCH] upgrade icns, remove pkg/errors --- go.mod | 5 +---- go.sum | 6 ++---- main.go | 45 ++++++++++++++++++++++----------------------- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/go.mod b/go.mod index 36910fc..e6dfdb6 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,6 @@ module git.yetaga.in/alazyreader/appify go 1.24.2 -require ( - github.com/JackMordaunt/icns v1.0.0 - github.com/pkg/errors v0.9.1 -) +require github.com/jackmordaunt/icns/v2 v2.2.7 require github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect diff --git a/go.sum b/go.sum index 132f64d..024b01b 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,4 @@ -github.com/JackMordaunt/icns v1.0.0 h1:41cNyWyQrG6beMw7m93LFK5o1GhefflsBTkauUkUtG8= -github.com/JackMordaunt/icns v1.0.0/go.mod h1:ubRqphS0f2OD07BuNaQSuw9uHUVQNBX5g38n6i2bdqM= +github.com/jackmordaunt/icns/v2 v2.2.7 h1:K/RbfvuzjmjVY5y4g+XENRs8ZZatwz4YnLHypa2KwQg= +github.com/jackmordaunt/icns/v2 v2.2.7/go.mod h1:ovoTxGguSuoUGKMk5Nn3R7L7BgMQkylsO+bblBuI22A= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/main.go b/main.go index eb379c8..fe67494 100644 --- a/main.go +++ b/main.go @@ -11,8 +11,7 @@ import ( "strings" "text/template" - "github.com/JackMordaunt/icns" - "github.com/pkg/errors" + "github.com/jackmordaunt/icns/v2" ) func main() { @@ -34,7 +33,7 @@ func run() error { flag.Parse() args := flag.Args() if len(args) < 1 { - return errors.New("missing executable argument") + return fmt.Errorf("missing executable argument") } bin := args[0] appname := *name + ".app" @@ -43,29 +42,29 @@ func run() error { resouresPath := filepath.Join(contentsPath, "Resources") binPath := filepath.Join(appPath, appname) if err := os.MkdirAll(appPath, 0777); err != nil { - return errors.Wrap(err, "os.MkdirAll appPath") + return fmt.Errorf("os.MkdirAll appPath: %w", err) } fdst, err := os.Create(binPath) if err != nil { - return errors.Wrap(err, "create bin") + return fmt.Errorf("create bin: %w", err) } defer fdst.Close() fsrc, err := os.Open(bin) if err != nil { if os.IsNotExist(err) { - return errors.New(bin + " not found") + return fmt.Errorf("%s not found", bin) } - return errors.Wrap(err, "os.Open") + return fmt.Errorf("os.Open: %w", err) } defer fsrc.Close() if _, err := io.Copy(fdst, fsrc); err != nil { - return errors.Wrap(err, "copy bin") + return fmt.Errorf("copy bin: %w", err) } if err := exec.Command("chmod", "+x", appPath).Run(); err != nil { - return errors.Wrap(err, "chmod: "+appPath) + return fmt.Errorf("chmod %s: %w", appPath, err) } if err := exec.Command("chmod", "+x", binPath).Run(); err != nil { - return errors.Wrap(err, "chmod: "+binPath) + return fmt.Errorf("chmod %s: %w", binPath, err) } id := *identifier if id == "" { @@ -74,7 +73,7 @@ func run() error { if *extraPlist != "" { b, err := os.ReadFile(*extraPlist) if err != nil { - return errors.Wrap(err, "error reading plist location: "+*extraPlist) + return fmt.Errorf("error reading plist location %s: %w", *extraPlist, err) } *extraPlist = string(b) } @@ -90,21 +89,21 @@ func run() error { if *icon != "" { iconPath, err := prepareIcons(*icon, resouresPath) if err != nil { - return errors.Wrap(err, "icon") + return fmt.Errorf("icon: %w", err) } info.IconFile = filepath.Base(iconPath) } tpl, err := template.New("template").Parse(infoPlistTemplate) if err != nil { - return errors.Wrap(err, "infoPlistTemplate") + return fmt.Errorf("infoPlistTemplate: %w", err) } fplist, err := os.Create(filepath.Join(contentsPath, "Info.plist")) if err != nil { - return errors.Wrap(err, "create Info.plist") + return fmt.Errorf("create Info.plist: %w", err) } defer fplist.Close() if err := tpl.Execute(fplist, info); err != nil { - return errors.Wrap(err, "execute Info.plist template") + return fmt.Errorf("execute Info.plist template: %w", err) } return nil } @@ -114,36 +113,36 @@ func prepareIcons(iconPath, resourcesPath string) (string, error) { fsrc, err := os.Open(iconPath) if err != nil { if os.IsNotExist(err) { - return "", errors.New("icon file not found") + return "", fmt.Errorf("icon file not found") } - return "", errors.Wrap(err, "open icon file") + return "", fmt.Errorf("open icon file: %w", err) } defer fsrc.Close() if err := os.MkdirAll(resourcesPath, 0777); err != nil { - return "", errors.Wrap(err, "os.MkdirAll resourcesPath") + return "", fmt.Errorf("os.MkdirAll resourcesPath: %w", err) } destFile := filepath.Join(resourcesPath, "icon.icns") fdst, err := os.Create(destFile) if err != nil { - return "", errors.Wrap(err, "create icon.icns file") + return "", fmt.Errorf("create icon.icns file: %w", err) } defer fdst.Close() switch ext { case ".icns": // just copy the .icns file _, err := io.Copy(fdst, fsrc) if err != nil { - return destFile, errors.Wrap(err, "copying "+iconPath) + return destFile, fmt.Errorf("copying %s: %w", iconPath, err) } case ".png", ".jpg", ".jpeg", ".gif": // process any images srcImg, _, err := image.Decode(fsrc) if err != nil { - return destFile, errors.Wrap(err, "decode image") + return destFile, fmt.Errorf("decode image: %w", err) } if err := icns.Encode(fdst, srcImg); err != nil { - return destFile, errors.Wrap(err, "generate icns file") + return destFile, fmt.Errorf("generate icns file: %w", err) } default: - return destFile, errors.New(ext + " icons not supported") + return destFile, fmt.Errorf("%s icons not supported", ext) } return destFile, nil }