-
Notifications
You must be signed in to change notification settings - Fork 0
/
remotelist.go
42 lines (37 loc) · 874 Bytes
/
remotelist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"context"
"flag"
"fmt"
"regexp"
"github.com/koron/goup/godlremote"
)
func remoteList(fs *flag.FlagSet, args []string) error {
var all bool
var match string
fs.BoolVar(&all, "all", false, "list all releases (archive and unstable)")
fs.StringVar(&match, "match", "", "show only matched versions (regexp)")
if err := fs.Parse(args); err != nil {
return err
}
var f func(godlremote.Release) bool
if match != "" {
rx, err := regexp.Compile(match)
if err != nil {
return fmt.Errorf("pattern error for -match: %w", err)
}
f = func(r godlremote.Release) bool {
return rx.MatchString(r.Version)
}
}
ctx := context.Background()
rels, err := godlremote.Download(ctx, all)
if err != nil {
return err
}
fmt.Println("Remote Version:")
for _, r := range rels.Filter(f) {
fmt.Printf(" %s\n", r.Version)
}
return nil
}