Skip to content

Commit

Permalink
fix default tag for wrap and bootstrap commands
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAbides committed Dec 22, 2023
1 parent 57546eb commit 24ee608
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
16 changes: 6 additions & 10 deletions cmd/bindown/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 10 additions & 3 deletions cmd/bindown/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"slices"
"strings"
"time"

"github.com/alecthomas/kong"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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,
})
Expand Down
11 changes: 10 additions & 1 deletion cmd/bindown/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down

0 comments on commit 24ee608

Please sign in to comment.