Skip to content

Commit 4ae6970

Browse files
committed
support different repos
1 parent afcb913 commit 4ae6970

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

cmd/makefile.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"errors"
5+
"sort"
56

67
"github.com/bakito/toolbox/pkg/makefile"
78
"github.com/go-resty/resty/v2"
@@ -26,6 +27,7 @@ var makefileCmd = &cobra.Command{
2627
if err != nil {
2728
return err
2829
}
30+
sort.Strings(args)
2931
return makefile.Generate(client, cmd.OutOrStderr(), mf, args...)
3032
},
3133
}

pkg/makefile/consts.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ $(LOCALBIN):
2424
.PHONY: {{.Name}}
2525
{{.Name}}: $({{.UpperName}}) ## Download {{.Name}} locally if necessary.
2626
$({{.UpperName}}): $(LOCALBIN)
27-
test -s $(LOCALBIN)/{{.Name}} || GOBIN=$(LOCALBIN) go install {{.Tool}}@$({{.UpperName}}_VERSION)
27+
test -s $(LOCALBIN)/{{.Name}} || GOBIN=$(LOCALBIN) go install {{.ToolName}}@$({{.UpperName}}_VERSION)
2828
{{- end }}
2929
3030
## Update Tools
3131
.PHONY: update-toolbox-tools
3232
update-toolbox-tools:
33+
$rm -f{{ range .Tools }} $(LOCALBIN)/{{.Name}}{{ end }}
3334
toolbox makefile -f $$(pwd)/Makefile{{- range .Tools }} \
3435
{{.Tool}}
3536
{{- end }}

pkg/makefile/make.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ func Generate(client *resty.Client, writer io.Writer, makefile string, tools ...
6565
}
6666

6767
func data(client *resty.Client, tool string) (toolData, error) {
68-
match := pattern.FindStringSubmatch(tool)
68+
toolRepo := strings.Split(tool, "@")
6969

70+
toolName := toolRepo[0]
71+
repo := toolRepo[len(toolRepo)-1]
72+
match := pattern.FindStringSubmatch(repo)
7073
t := toolData{}
7174

7275
if len(match) != 2 {
@@ -78,9 +81,10 @@ func data(client *resty.Client, tool string) (toolData, error) {
7881
return t, err
7982
}
8083

81-
parts := strings.Split(tool, "/")
84+
parts := strings.Split(toolName, "/")
8285

8386
t.Version = ghr.TagName
87+
t.ToolName = toolName
8488
t.Tool = tool
8589
t.Name = parts[len(parts)-1]
8690
t.UpperName = strings.ReplaceAll(strings.ToUpper(t.Name), "-", "_")
@@ -92,4 +96,5 @@ type toolData struct {
9296
UpperName string `json:"UpperName"`
9397
Version string `json:"Version"`
9498
Tool string `json:"Tool"`
99+
ToolName string `json:"ToolName"`
95100
}

testdata/Makefile.content.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ $(TOOLBOX): $(LOCALBIN)
2121
## Update Tools
2222
.PHONY: update-toolbox-tools
2323
update-toolbox-tools:
24+
$rm -f $(LOCALBIN)/toolbox
2425
toolbox makefile -f $$(pwd)/Makefile \
2526
github.com/bakito/toolbox
2627
## toolbox - end

testdata/Makefile.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ $(TOOLBOX): $(LOCALBIN)
1919
## Update Tools
2020
.PHONY: update-toolbox-tools
2121
update-toolbox-tools:
22+
$rm -f $(LOCALBIN)/toolbox
2223
toolbox makefile -f $$(pwd)/Makefile \
2324
github.com/bakito/toolbox
2425
## toolbox - end

0 commit comments

Comments
 (0)