icns

Easily create .icns files (Mac Icons) with this Go library or the included CLI.
Log | Files | Refs | LICENSE

commit 1603cb1eb48f3f5767cb91baa28db86586dfe8e2
parent 6e0cc7f2a9e45569c000b36817ddbdebe8f4ef7a
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Fri, 18 Sep 2026 16:09:35 -0400

cmd/icnsify: report the build with a version flag

A tool shipped through brew, scoop and winget should be able to say what it
is, and the release already stamped a commit, date and builder that nothing
declared, so the linker quietly discarded them.

Diffstat:
Mcmd/icnsify/doc.go | 33++++++++++++++++++++++++++++++---
Mcmd/icnsify/main.go | 7+++++++
2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/cmd/icnsify/doc.go b/cmd/icnsify/doc.go @@ -6,8 +6,28 @@ import ( "strconv" ) -// version is stamped by goreleaser at build time. -var version = "master" +// Stamped by goreleaser at build time, through the linker. +var ( + version = "master" + commit = "" + date = "" + builtBy = "" +) + +// buildInfo renders the version and whatever else the build stamped. +func buildInfo() string { + out := "icnsify " + version + for _, part := range []struct{ label, value string }{ + {"commit", commit}, + {"built", date}, + {"by", builtBy}, + } { + if part.value != "" { + out += fmt.Sprintf(", %s %s", part.label, part.value) + } + } + return out +} // option records a flag registered under both a long and a short name, so // usage can list the pair once, GNU style. @@ -32,9 +52,16 @@ func intFlag(p *int, long, short string, def int, usage string) { options = append(options, option{long: long, short: short, def: strconv.Itoa(def), usage: usage}) } +// boolFlag registers a boolean option reachable as --long or -short. +func boolFlag(p *bool, long, short string, usage string) { + flag.BoolVar(p, long, false, usage) + flag.BoolVar(p, short, false, usage) + options = append(options, option{long: long, short: short, usage: usage}) +} + func usage() { w := flag.CommandLine.Output() - fmt.Fprintf(w, "icnsify %s\n\nUsage: icnsify [-i input] [-o output] [-r quality]\n\nOptions:\n", version) + fmt.Fprintf(w, "%s\n\nUsage: icnsify [-i input] [-o output] [-r quality]\n\nOptions:\n", buildInfo()) for _, o := range options { fmt.Fprintf(w, " -%s, --%s\n %s", o.short, o.long, o.usage) if o.def != "" && o.def != "0" { diff --git a/cmd/icnsify/main.go b/cmd/icnsify/main.go @@ -41,9 +41,16 @@ func run() error { "Output path, defaults to <path/to/image>.(icns|png) depending on input.") intFlag(&resize, "resize", "r", 5, "Quality of resize algorithm, 0 to 5 from fastest to slowest.") + var showVersion bool + boolFlag(&showVersion, "version", "v", "Print the version and exit.") flag.Usage = usage flag.Parse() + if showVersion { + fmt.Println(buildInfo()) + return nil + } + var ( input io.Reader output io.Writer