Skip to content

Commit

Permalink
Merge pull request #138 from WillAbides/builddep
Browse files Browse the repository at this point in the history
dependency add-by-urls and add-by-github-release
  • Loading branch information
WillAbides authored May 9, 2023
2 parents 25b5c73 + bdcdacf commit 2e08cce
Show file tree
Hide file tree
Showing 10 changed files with 1,678 additions and 75 deletions.
56 changes: 29 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,33 +305,35 @@ Flags:
-q, --quiet suppress output to stdout

Commands:
download download a dependency but don't extract or install it
extract download and extract a dependency but don't install it
install download, extract and install a dependency
format formats the config file
dependency list list configured dependencies
dependency add add a template-based dependency
dependency remove remove a dependency
dependency info info about a dependency
dependency show-config show dependency config
dependency update-vars update dependency vars
dependency validate validate that installs work
template list list templates
template remove remove a template
template update-from-source update a template from source
template update-vars update template vars
template-source list list configured template sources
template-source add add a template source
template-source remove remove a template source
supported-system list list supported systems
supported-system add add a supported system
supported-system remove remove a supported system
checksums add add checksums to the config file
checksums prune remove unnecessary checksums from the config file
init create an empty config file
cache clear clear the cache
version show bindown version
install-completions install shell completions
download download a dependency but don't extract or install it
extract download and extract a dependency but don't install it
install download, extract and install a dependency
format formats the config file
dependency list list configured dependencies
dependency add add a template-based dependency
dependency add-by-urls add a dependency by urls
dependency add-by-github-release add a dependency by github release
dependency remove remove a dependency
dependency info info about a dependency
dependency show-config show dependency config
dependency update-vars update dependency vars
dependency validate validate that installs work
template list list templates
template remove remove a template
template update-from-source update a template from source
template update-vars update template vars
template-source list list configured template sources
template-source add add a template source
template-source remove remove a template source
supported-system list list supported systems
supported-system add add a supported system
supported-system remove remove a supported system
checksums add add checksums to the config file
checksums prune remove unnecessary checksums from the config file
init create an empty config file
cache clear clear the cache
version show bindown version
install-completions install shell completions

Run "bindown <command> --help" for more information on a command.
```
Expand Down
93 changes: 86 additions & 7 deletions cmd/bindown/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import (
"bufio"
"encoding/json"
"fmt"
"regexp"
"strings"

"github.com/willabides/bindown/v3"
"github.com/willabides/bindown/v3/internal/builddep"
"gopkg.in/yaml.v2"
)

type dependencyCmd struct {
List dependencyListCmd `kong:"cmd,help='list configured dependencies'"`
Add dependencyAddCmd `kong:"cmd,help='add a template-based dependency'"`
Remove dependencyRemoveCmd `kong:"cmd,help='remove a dependency'"`
Info dependencyInfoCmd `kong:"cmd,help='info about a dependency'"`
ShowConfig dependencyShowConfigCmd `kong:"cmd,help='show dependency config'"`
UpdateVars dependencyUpdateVarsCmd `kong:"cmd,help='update dependency vars'"`
Validate dependencyValidateCmd `kong:"cmd,help='validate that installs work'"`
List dependencyListCmd `kong:"cmd,help='list configured dependencies'"`
Add dependencyAddCmd `kong:"cmd,help='add a template-based dependency'"`
AddByUrls dependencyAddByUrlsCmd `kong:"cmd,help='add a dependency by urls'"`
AddByGithubRelease dependencyAddByGithubReleaseCmd `kong:"cmd,help='add a dependency by github release'"`
Remove dependencyRemoveCmd `kong:"cmd,help='remove a dependency'"`
Info dependencyInfoCmd `kong:"cmd,help='info about a dependency'"`
ShowConfig dependencyShowConfigCmd `kong:"cmd,help='show dependency config'"`
UpdateVars dependencyUpdateVarsCmd `kong:"cmd,help='update dependency vars'"`
Validate dependencyValidateCmd `kong:"cmd,help='validate that installs work'"`
}

type dependencyUpdateVarsCmd struct {
Expand Down Expand Up @@ -213,6 +217,81 @@ func (c *dependencyAddCmd) Run(ctx *runContext) error {
return config.Write(ctx.rootCmd.JSONConfig)
}

type dependencyAddByUrlsCmd struct {
Name string `kong:"arg,help='dependency name'"`
Version string `kong:"arg,help='dependency version'"`
URL []string `kong:"arg,help='dependency URL'"`
Force bool `kong:"name=force,help='overwrite existing dependency'"`
Experimental bool `kong:"required,name=experimental,help='enable experimental features',env='BINDOWN_EXPERIMENTAL'"`
}

func (c *dependencyAddByUrlsCmd) Run(ctx *runContext) error {
config, err := loadConfigFile(ctx, true)
if err != nil {
return err
}
if config.Dependencies != nil && config.Dependencies[c.Name] != nil && !c.Force {
return fmt.Errorf("dependency %q already exists", c.Name)
}
err = builddep.AddDependency(ctx, &config.Config, c.Name, c.Version, c.URL)
if err != nil {
return err
}
return config.Write(ctx.rootCmd.JSONConfig)
}

type dependencyAddByGithubReleaseCmd struct {
Release string `kong:"arg,help='github release URL or \"owner/repo(@tag)\"'"`
Name string `kong:"name to use instead of repo name"`
Version string `kong:"version to use instead of release tag"`
Force bool `kong:"name=force,help='overwrite existing dependency'"`
Experimental bool `kong:"required,name=experimental,help='enable experimental features',env='BINDOWN_EXPERIMENTAL'"`
GithubToken string `kong:"hidden,env='GITHUB_TOKEN'"`
}

var (
releaseShortExp = regexp.MustCompile(`^([^/]+)/([^/^@]+)@?(.+)?$`)
releaseURLExp = regexp.MustCompile(`^https://github\.com/([^/]+)/([^/]+)/releases/tag/([^/]+)`)
)

func (c *dependencyAddByGithubReleaseCmd) Run(ctx *runContext) error {
config, err := loadConfigFile(ctx, true)
if err != nil {
return err
}
var owner, repo, tag string
switch {
case releaseURLExp.MatchString(c.Release):
m := releaseURLExp.FindStringSubmatch(c.Release)
owner, repo, tag = m[1], m[2], m[3]
case releaseShortExp.MatchString(c.Release):
m := releaseShortExp.FindStringSubmatch(c.Release)
owner, repo, tag = m[1], m[2], m[3]
default:
return fmt.Errorf(`invalid release URL or "owner/repo(@tag)"`)
}
urls, releaseVer, err := builddep.QueryGitHubRelease(ctx, fmt.Sprintf("%s/%s", owner, repo), tag, c.GithubToken)
if err != nil {
return err
}
ver := c.Version
if ver == "" {
ver = releaseVer
}
name := c.Name
if name == "" {
name = repo
}
if config.Dependencies != nil && config.Dependencies[name] != nil && !c.Force {
return fmt.Errorf("dependency %q already exists", name)
}
err = builddep.AddDependency(ctx, &config.Config, name, ver, urls)
if err != nil {
return err
}
return config.Write(ctx.rootCmd.JSONConfig)
}

type dependencyValidateCmd struct {
Dependency string `kong:"arg,predictor=bin"`
Systems []bindown.SystemInfo `kong:"name=system,predictor=allSystems"`
Expand Down
56 changes: 29 additions & 27 deletions docs/clihelp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,34 @@ Flags:
-q, --quiet suppress output to stdout

Commands:
download download a dependency but don't extract or install it
extract download and extract a dependency but don't install it
install download, extract and install a dependency
format formats the config file
dependency list list configured dependencies
dependency add add a template-based dependency
dependency remove remove a dependency
dependency info info about a dependency
dependency show-config show dependency config
dependency update-vars update dependency vars
dependency validate validate that installs work
template list list templates
template remove remove a template
template update-from-source update a template from source
template update-vars update template vars
template-source list list configured template sources
template-source add add a template source
template-source remove remove a template source
supported-system list list supported systems
supported-system add add a supported system
supported-system remove remove a supported system
checksums add add checksums to the config file
checksums prune remove unnecessary checksums from the config file
init create an empty config file
cache clear clear the cache
version show bindown version
install-completions install shell completions
download download a dependency but don't extract or install it
extract download and extract a dependency but don't install it
install download, extract and install a dependency
format formats the config file
dependency list list configured dependencies
dependency add add a template-based dependency
dependency add-by-urls add a dependency by urls
dependency add-by-github-release add a dependency by github release
dependency remove remove a dependency
dependency info info about a dependency
dependency show-config show dependency config
dependency update-vars update dependency vars
dependency validate validate that installs work
template list list templates
template remove remove a template
template update-from-source update a template from source
template update-vars update template vars
template-source list list configured template sources
template-source add add a template source
template-source remove remove a template source
supported-system list list supported systems
supported-system add add a supported system
supported-system remove remove a supported system
checksums add add checksums to the config file
checksums prune remove unnecessary checksums from the config file
init create an empty config file
cache clear clear the cache
version show bindown version
install-completions install shell completions

Run "bindown <command> --help" for more information on a command.
35 changes: 31 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,62 @@ module github.com/willabides/bindown/v3
go 1.20

require (
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/Masterminds/semver/v3 v3.1.1
github.com/alecthomas/kong v0.7.1
github.com/google/go-cmp v0.5.8
github.com/google/go-cmp v0.5.9
github.com/google/go-github/v52 v52.0.0
github.com/mholt/archiver/v3 v3.5.1
github.com/mholt/archiver/v4 v4.0.0-alpha.8
github.com/posener/complete v1.2.3
github.com/qri-io/jsonschema v0.2.1
github.com/rogpeppe/go-internal v1.10.0
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.7.1
github.com/willabides/kongplete v0.3.0
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
golang.org/x/oauth2 v0.8.0
golang.org/x/sync v0.2.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/bodgit/plumbing v1.2.0 // indirect
github.com/bodgit/sevenzip v1.3.0 // indirect
github.com/bodgit/windows v1.0.0 // indirect
github.com/cloudflare/circl v1.1.0 // indirect
github.com/connesc/cipherio v0.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/nwaples/rardecode v1.1.2 // indirect
github.com/pierrec/lz4/v4 v4.1.12 // indirect
github.com/nwaples/rardecode/v2 v2.0.0-beta.2 // indirect
github.com/pierrec/lz4/v4 v4.1.15 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/qri-io/jsonpointer v0.1.1 // indirect
github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab // indirect
github.com/therootcompany/xz v1.0.1 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
go4.org v0.0.0-20200411211856-f5505b9728dd // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
)
Loading

0 comments on commit 2e08cce

Please sign in to comment.