add ls-remote cmd
This commit is contained in:
parent
39467ef06f
commit
2294f51fcf
50
cmd/cmd.go
50
cmd/cmd.go
|
@ -101,6 +101,36 @@ Release(s) folder will be removed from "~/.local/doggofetcher" and thus not avai
|
|||
Usage: "Execute a go command",
|
||||
Action: execCommand,
|
||||
},
|
||||
{
|
||||
Name: "ls-remote",
|
||||
Usage: "List all remote references",
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "rc",
|
||||
Usage: "Allow \"rc\" version to be fetched",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "beta",
|
||||
Usage: "Allow \"beta\" version to be fetched",
|
||||
},
|
||||
},
|
||||
Action: lsRemote,
|
||||
},
|
||||
{
|
||||
Name: "ls-remote",
|
||||
Usage: "List all remote references",
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "rc",
|
||||
Usage: "Allow \"rc\" version to be fetched",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "beta",
|
||||
Usage: "Allow \"beta\" version to be fetched",
|
||||
},
|
||||
},
|
||||
Action: lsRemote,
|
||||
},
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{Name: "verbose", Aliases: []string{"v"}, Usage: "Enable verbose mode"},
|
||||
|
@ -108,9 +138,7 @@ Release(s) folder will be removed from "~/.local/doggofetcher" and thus not avai
|
|||
}
|
||||
)
|
||||
|
||||
// todo: ls-remote (list remote releases)
|
||||
// todo: alias (set alias for a release)
|
||||
// todo: auto-use (automatically switch when changing directory)
|
||||
|
||||
func Execute() error {
|
||||
cli.VersionFlag = &cli.BoolFlag{
|
||||
|
@ -351,3 +379,21 @@ func execCommand(ctx *cli.Context) error {
|
|||
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func lsRemote(ctx *cli.Context) error {
|
||||
refs, err := pkg.NewTags("", ctx.Context).GetTagsRef()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, r := range refs {
|
||||
ref := r.GetRef()
|
||||
if (!ctx.Bool("rc") && strings.Contains(ref, "rc")) || (!ctx.Bool("beta") && strings.Contains(ref, "beta")) {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Println(strings.Split(r.GetRef(), "/")[2])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
5
go.sum
5
go.sum
|
@ -3,12 +3,10 @@ github.com/briandowns/spinner v1.18.1/go.mod h1:mQak9GHqbspjC/5iUx3qMlIho8xBS/pp
|
|||
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||
github.com/google/go-github/v45 v45.1.0 h1:SbUjHMRiCe9cHfu6Me4idWxLQEV8ZW9DLPz69zopyWo=
|
||||
github.com/google/go-github/v45 v45.1.0/go.mod h1:FObaZJEDSTa/WGCzZ2Z3eoCDXWJKMenWWTrd8jrta28=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
|
@ -17,14 +15,12 @@ github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx
|
|||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/urfave/cli/v2 v2.8.1 h1:CGuYNZF9IKZY/rfBe3lJpccSoIY1ytfvmgQT90cNOl4=
|
||||
github.com/urfave/cli/v2 v2.8.1/go.mod h1:Z41J9TPoffeoqP0Iza0YbAhGvymRdZAd2uPmZ5JxRdY=
|
||||
|
@ -37,5 +33,4 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JC
|
|||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
10
pkg/tags.go
10
pkg/tags.go
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
type TagsAction interface {
|
||||
GetRelease(beta, rc bool) (string, error)
|
||||
getTagsRef() ([]*github.Reference, error)
|
||||
GetTagsRef() ([]*github.Reference, error)
|
||||
getLatestTag(beta, rc bool) (string, error)
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ func (t Tags) GetRelease(beta, rc bool) (string, error) {
|
|||
return t.getLatestTag(beta, rc)
|
||||
}
|
||||
|
||||
refs, err := t.getTagsRef()
|
||||
refs, err := t.GetTagsRef()
|
||||
if err != nil {
|
||||
if err == ErrEmptyTags {
|
||||
return "", nil
|
||||
|
@ -87,11 +87,11 @@ func (t Tags) GetRelease(beta, rc bool) (string, error) {
|
|||
return "", ErrEmptyTags
|
||||
}
|
||||
|
||||
// getTagsRef retrieves all tags from golang/go
|
||||
// GetTagsRef retrieves all tags from golang/go
|
||||
//
|
||||
// Returns a list of tags reference if there is as least one
|
||||
// or an error otherwise.
|
||||
func (t Tags) getTagsRef() ([]*github.Reference, error) {
|
||||
func (t Tags) GetTagsRef() ([]*github.Reference, error) {
|
||||
refs, response, err := t.client.Git.ListMatchingRefs(t.ctx, "golang", "go", &github.ReferenceListOptions{
|
||||
Ref: "tags/go",
|
||||
})
|
||||
|
@ -114,7 +114,7 @@ func (t Tags) getTagsRef() ([]*github.Reference, error) {
|
|||
//
|
||||
// Returns the latest release or an error
|
||||
func (t Tags) getLatestTag(beta, rc bool) (string, error) {
|
||||
refs, err := t.getTagsRef()
|
||||
refs, err := t.GetTagsRef()
|
||||
if err != nil {
|
||||
if err == ErrEmptyTags {
|
||||
return "", nil
|
||||
|
|
Reference in New Issue