diff --git a/cmd/bindown/bootstrap.go b/cmd/bindown/bootstrap.go index 639a6e3..97c7bd0 100644 --- a/cmd/bindown/bootstrap.go +++ b/cmd/bindown/bootstrap.go @@ -9,24 +9,20 @@ import ( bootstrapper "github.com/willabides/bindown/v4/internal/build-bootstrapper" ) -func defaultBootstrapTag() string { - if Version == "unknown" { - return "" - } - return "v" + Version -} - type bootstrapCmd struct { - Tag string `kong:"hidden,default=${bootstrap_tag_default}"` + Tag string `kong:"hidden"` BaseURL string `kong:"hidden,name='base-url',default='https://github.com'"` Output string `kong:"help='output file, writes to stdout if not set',type='path'"` } func (c *bootstrapCmd) Run(ctx *runContext) error { - if c.Tag == "" { + tag := c.Tag + if tag == "" { + tag = getVersion() + } + if tag == "" { return fmt.Errorf("version is required") } - tag := c.Tag if !strings.HasPrefix(tag, "v") { tag = "v" + tag } diff --git a/cmd/bindown/cli.go b/cmd/bindown/cli.go index 321f830..e179de9 100644 --- a/cmd/bindown/cli.go +++ b/cmd/bindown/cli.go @@ -6,6 +6,7 @@ import ( "io" "os" "slices" + "strings" "time" "github.com/alecthomas/kong" @@ -40,7 +41,6 @@ var kongVars = kong.Vars{ "install_to_cache_help": `install to cache instead of install dir`, "install_wrapper_help": `install a wrapper script instead of the binary`, "install_bindown_help": `path to bindown executable to use in wrapper`, - "bootstrap_tag_default": defaultBootstrapTag(), } type rootCmd struct { @@ -326,11 +326,18 @@ type wrapCmd struct { Output string `kong:"type=path,name=output,type=file,help=${output_help}"` AllowMissingChecksum bool `kong:"name=allow-missing-checksum,help=${allow_missing_checksum}"` BindownExec string `kong:"name=bindown,help=${install_bindown_help}"` - BindownTag string `kong:"hidden,default=${bootstrap_tag_default}"` + BindownTag string `kong:"hidden"` BaseURL string `kong:"hidden,name='base-url',default='https://github.com'"` } func (d *wrapCmd) Run(ctx *runContext) error { + tag := d.BindownTag + if tag == "" { + tag = getVersion() + } + if tag != "" && !strings.HasPrefix(tag, "v") { + tag = "v" + tag + } config, err := loadConfigFile(ctx, false) if err != nil { return err @@ -341,7 +348,7 @@ func (d *wrapCmd) Run(ctx *runContext) error { BindownExec: d.BindownExec, Stdout: ctx.stdout, AllDeps: d.All, - BindownTag: d.BindownTag, + BindownTag: tag, BindownWrapped: os.Getenv("BINDOWN_WRAPPED"), BaseURL: d.BaseURL, }) diff --git a/cmd/bindown/version.go b/cmd/bindown/version.go index f31ac28..f0f4744 100644 --- a/cmd/bindown/version.go +++ b/cmd/bindown/version.go @@ -4,8 +4,17 @@ import ( "fmt" ) +const defaultVersion = "unknown" + // Version the version to display for `bindown version` -var Version = "unknown" +var Version = defaultVersion + +func getVersion() string { + if Version == defaultVersion { + return "" + } + return Version +} type versionCmd struct{}