Skip to content

Commit 6583239

Browse files
authored
Merge pull request #23 from gildas/release/0.16.0
Merge release/0.16.0
2 parents 7ada1e2 + bb0efa0 commit 6583239

89 files changed

Lines changed: 1759 additions & 522 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ TAR ?= tar
6363
ZIP ?= zip
6464
MOVE ?= mv
6565
COPY ?= cp -f
66+
AWK ?= awk
6667

6768
# Flags
6869
#MAKEFLAGS += --silent
@@ -117,15 +118,15 @@ help: Makefile; ## Display this help
117118
@$P "$(PROJECT) version $(VERSION) build " $(BUILD) " in $(BRANCH) branch"
118119
@$P "Make recipes you can run: "
119120
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) |\
120-
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
121+
$(AWK) 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
121122

122123
all: test build; ## Test and Build the application
123124

124125
gendoc: __gendoc_init__ $(BIN_DIR)/$(PROJECT).pdf; @ ## Generate the PDF documentation
125126

126127
publish: __publish_init__ __publish_binaries__ __publish_snap__; @ ## Publish the binaries to the Repository
127128

128-
archive: __archive_init__ __archive_all__ __archive_chocolatey__ __archive_debian__ __archive_rpm__ __archive_snap__ ; @ ## Archive the binaries
129+
archive: __archive_init__ __archive_all__ __archive_debian__ __archive_rpm__ __archive_chocolatey__ __archive_snap__ ; @ ## Archive the binaries
129130

130131
build: __build_init__ __build_all__; @ ## Build the application for all platforms
131132

@@ -225,13 +226,13 @@ __start__: stop $(BIN_DIR)/$(GOOS)/$(PROJECT) | $(TMP_DIR) $(LOG_DIR); $(info $(
225226
__publish_init__:;
226227
__publish_binaries__: __archive_all__ __archive_debian__ __archive_rpm__
227228
$(info $(M) Uploading the binary packages...)
228-
$Q $(foreach archive, $(wildcard $(BIN_DIR)/*.tar.gz), gh release upload v$(VERSION) $(archive) ;)
229-
$Q $(foreach archive, $(wildcard $(BIN_DIR)/*.zip), gh release upload v$(VERSION) $(archive) ;)
230-
$Q $(foreach archive, $(wildcard $(BIN_DIR)/*.7z), gh release upload v$(VERSION) $(archive) ;)
229+
$Q $(foreach archive, $(wildcard $(BIN_DIR)/*$(VERSION)*.tar.gz), gh release upload v$(VERSION) $(archive) ;)
230+
$Q $(foreach archive, $(wildcard $(BIN_DIR)/*$(VERSION)*.zip), gh release upload v$(VERSION) $(archive) ;)
231+
$Q $(foreach archive, $(wildcard $(BIN_DIR)/*$(VERSION)*.7z), gh release upload v$(VERSION) $(archive) ;)
231232
$(info $(M) Uploading the Debian packages...)
232-
$Q $(foreach archive, $(wildcard $(BIN_DIR)/*.deb), gh release upload v$(VERSION) $(archive) ;)
233+
$Q $(foreach archive, $(wildcard $(BIN_DIR)/*$(VERSION)*.deb), gh release upload v$(VERSION) $(archive) ;)
233234
$(info $(M) Uploading the RPM packages...)
234-
$Q $(foreach archive, $(wildcard $(BIN_DIR)/*.rpm), gh release upload v$(VERSION) $(archive) ;)
235+
$Q $(foreach archive, $(wildcard $(BIN_DIR)/*$(VERSION)*.rpm), gh release upload v$(VERSION) $(archive) ;)
235236

236237
__publish_snap__: \
237238
$(TMP_DIR)/__publish_snap__ \
@@ -314,40 +315,40 @@ __fetch_modules__: ; $(info $(M) Fetching Modules...)
314315
$Q $(GO) mod download
315316

316317
$(BIN_DIR)/darwin: $(BIN_DIR) ; $(MKDIR)
317-
$(BIN_DIR)/darwin/amd64: $(BIN_DIR) ; $(MKDIR)
318+
$(BIN_DIR)/darwin/amd64: $(BIN_DIR)/darwin ; $(MKDIR)
318319
$(BIN_DIR)/darwin/amd64/$(PROJECT): export GOOS=darwin
319320
$(BIN_DIR)/darwin/amd64/$(PROJECT): export GOARCH=amd64
320321
$(BIN_DIR)/darwin/amd64/$(PROJECT): $(GOFILES) $(ASSETS) | $(BIN_DIR)/darwin/amd64; $(info $(M) building application for darwin Intel)
321322
$Q $(GO) build $(if $V,-v) $(LDFLAGS) -o $@ .
322323

323-
$(BIN_DIR)/darwin/arm64: $(BIN_DIR) ; $(MKDIR)
324+
$(BIN_DIR)/darwin/arm64: $(BIN_DIR)/darwin ; $(MKDIR)
324325
$(BIN_DIR)/darwin/arm64/$(PROJECT): export GOOS=darwin
325326
$(BIN_DIR)/darwin/arm64/$(PROJECT): export GOARCH=arm64
326327
$(BIN_DIR)/darwin/arm64/$(PROJECT): $(GOFILES) $(ASSETS) | $(BIN_DIR)/darwin/arm64; $(info $(M) building application for darwin M1)
327328
$Q $(GO) build $(if $V,-v) $(LDFLAGS) -o $@ .
328329

329330
$(BIN_DIR)/linux: $(BIN_DIR) ; $(MKDIR)
330-
$(BIN_DIR)/linux/amd64: $(BIN_DIR) ; $(MKDIR)
331+
$(BIN_DIR)/linux/amd64: $(BIN_DIR)/linux ; $(MKDIR)
331332
$(BIN_DIR)/linux/amd64/$(PROJECT): export GOOS=linux
332333
$(BIN_DIR)/linux/amd64/$(PROJECT): export GOARCH=amd64
333334
$(BIN_DIR)/linux/amd64/$(PROJECT): $(GOFILES) $(ASSETS) | $(BIN_DIR)/linux/amd64; $(info $(M) building application for linux amd64)
334335
$Q $(GO) build $(if $V,-v) $(LDFLAGS) -o $@ .
335336

336-
$(BIN_DIR)/linux/arm64: $(BIN_DIR) ; $(MKDIR)
337+
$(BIN_DIR)/linux/arm64: $(BIN_DIR)/linux ; $(MKDIR)
337338
$(BIN_DIR)/linux/arm64/$(PROJECT): export GOOS=linux
338339
$(BIN_DIR)/linux/arm64/$(PROJECT): export GOARCH=arm64
339340
$(BIN_DIR)/linux/arm64/$(PROJECT): $(GOFILES) $(ASSETS) | $(BIN_DIR)/linux/arm64; $(info $(M) building application for linux arm64)
340341
$Q $(GO) build $(if $V,-v) $(LDFLAGS) -o $@ .
341342

342343
$(BIN_DIR)/windows: $(BIN_DIR) ; $(MKDIR)
343-
$(BIN_DIR)/windows/amd64: $(BIN_DIR) ; $(MKDIR)
344+
$(BIN_DIR)/windows/amd64: $(BIN_DIR)/windows ; $(MKDIR)
344345
$(BIN_DIR)/windows/amd64/$(PROJECT): $(BIN_DIR)/windows/amd64/$(PROJECT).exe;
345346
$(BIN_DIR)/windows/amd64/$(PROJECT).exe: export GOOS=windows
346347
$(BIN_DIR)/windows/amd64/$(PROJECT).exe: export GOARCH=amd64
347348
$(BIN_DIR)/windows/amd64/$(PROJECT).exe: $(GOFILES) $(ASSETS) | $(BIN_DIR)/windows/amd64; $(info $(M) building application for windows amd64)
348349
$Q $(GO) build $(if $V,-v) $(LDFLAGS) -o $@ .
349350

350-
$(BIN_DIR)/windows/arm64: $(BIN_DIR) ; $(MKDIR)
351+
$(BIN_DIR)/windows/arm64: $(BIN_DIR)/windows ; $(MKDIR)
351352
$(BIN_DIR)/windows/arm64/$(PROJECT): $(BIN_DIR)/windows/arm64/$(PROJECT).exe;
352353
$(BIN_DIR)/windows/arm64/$(PROJECT).exe: export GOOS=windows
353354
$(BIN_DIR)/windows/arm64/$(PROJECT).exe: export GOARCH=arm64

cmd/artifact/artifact.go

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,52 @@ var Command = &cobra.Command{
3232
},
3333
}
3434

35-
// GetHeader gets the header for a table
35+
var columns = common.Columns[Artifact]{
36+
{Name: "name", DefaultSorter: true, Compare: func(a, b Artifact) bool {
37+
return strings.Compare(strings.ToLower(a.Name), strings.ToLower(b.Name)) == -1
38+
}},
39+
{Name: "size", DefaultSorter: false, Compare: func(a, b Artifact) bool {
40+
return a.Size < b.Size
41+
}},
42+
{Name: "downloads", DefaultSorter: false, Compare: func(a, b Artifact) bool {
43+
return a.Downloads < b.Downloads
44+
}},
45+
{Name: "owner", DefaultSorter: false, Compare: func(a, b Artifact) bool {
46+
return strings.Compare(strings.ToLower(a.User.Username), strings.ToLower(b.User.Username)) == -1
47+
}},
48+
}
49+
50+
// GetHeaders gets the header for a table
3651
//
3752
// implements common.Tableable
38-
func (artifact Artifact) GetHeader(short bool) []string {
53+
func (artifact Artifact) GetHeaders(cmd *cobra.Command) []string {
54+
if cmd != nil && cmd.Flag("columns") != nil && cmd.Flag("columns").Changed {
55+
if columns, err := cmd.Flags().GetStringSlice("columns"); err == nil {
56+
return core.Map(columns, func(column string) string { return strings.ReplaceAll(column, "_", " ") })
57+
}
58+
}
3959
return []string{"Name", "Size", "Downloads", "Owner"}
4060
}
4161

4262
// GetRow gets the row for a table
4363
//
4464
// implements common.Tableable
4565
func (artifact Artifact) GetRow(headers []string) []string {
46-
return []string{
47-
artifact.Name,
48-
fmt.Sprintf("%d", artifact.Size),
49-
fmt.Sprintf("%d", artifact.Downloads),
50-
artifact.User.Name,
66+
var row []string
67+
68+
for _, header := range headers {
69+
switch strings.ToLower(header) {
70+
case "name":
71+
row = append(row, artifact.Name)
72+
case "size":
73+
row = append(row, fmt.Sprintf("%d", artifact.Size))
74+
case "downloads":
75+
row = append(row, fmt.Sprintf("%d", artifact.Downloads))
76+
case "owner":
77+
row = append(row, artifact.User.Name)
78+
}
5179
}
80+
return row
5281
}
5382

5483
// GetArtifactNames gets the names of the artifacts

cmd/artifact/artifacts.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package artifact
22

3+
import "github.com/spf13/cobra"
4+
35
type Artifacts []Artifact
46

5-
// GetHeader gets the headers for the list command
7+
// GetHeaders gets the headers for the list command
68
//
79
// implements common.Tableables
8-
func (artifacts Artifacts) GetHeader() []string {
9-
return Artifact{}.GetHeader(false)
10+
func (artifacts Artifacts) GetHeaders(cmd *cobra.Command) []string {
11+
return Artifact{}.GetHeaders(cmd)
1012
}
1113

1214
// GetRowAt gets the row for the list command

cmd/artifact/delete.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,13 @@ var deleteCmd = &cobra.Command{
2121
}
2222

2323
var deleteOptions struct {
24-
Repository string
25-
StopOnError bool
26-
WarnOnError bool
27-
IgnoreErrors bool
24+
Repository string
2825
}
2926

3027
func init() {
3128
Command.AddCommand(deleteCmd)
3229

3330
deleteCmd.Flags().StringVar(&deleteOptions.Repository, "repository", "", "Repository to delete artifacts from. Defaults to the current repository")
34-
deleteCmd.Flags().BoolVar(&deleteOptions.StopOnError, "stop-on-error", false, "Stop on error")
35-
deleteCmd.Flags().BoolVar(&deleteOptions.WarnOnError, "warn-on-error", false, "Warn on error")
36-
deleteCmd.Flags().BoolVar(&deleteOptions.IgnoreErrors, "ignore-errors", false, "Ignore errors")
37-
deleteCmd.MarkFlagsMutuallyExclusive("stop-on-error", "warn-on-error", "ignore-errors")
3831
}
3932

4033
func deleteValidArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {

cmd/artifact/download.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ var downloadCmd = &cobra.Command{
2121
}
2222

2323
var downloadOptions struct {
24-
Repository string
25-
Destination string
26-
Progress bool
27-
StopOnError bool
28-
WarnOnError bool
29-
IgnoreErrors bool
24+
Repository string
25+
Destination string
26+
Progress bool
3027
}
3128

3229
func init() {
@@ -35,10 +32,6 @@ func init() {
3532
downloadCmd.Flags().StringVar(&downloadOptions.Repository, "repository", "", "Repository to download artifacts from. Defaults to the current repository")
3633
downloadCmd.Flags().StringVar(&downloadOptions.Destination, "destination", "", "Destination folder to download the artifact to. Defaults to the current folder")
3734
downloadCmd.Flags().BoolVar(&downloadOptions.Progress, "progress", false, "Show progress")
38-
downloadCmd.Flags().BoolVar(&downloadOptions.StopOnError, "stop-on-error", false, "Stop on error")
39-
downloadCmd.Flags().BoolVar(&downloadOptions.WarnOnError, "warn-on-error", false, "Warn on error")
40-
downloadCmd.Flags().BoolVar(&downloadOptions.IgnoreErrors, "ignore-errors", false, "Ignore errors")
41-
downloadCmd.MarkFlagsMutuallyExclusive("stop-on-error", "warn-on-error", "ignore-errors")
4235
_ = downloadCmd.MarkFlagDirname("destination")
4336
}
4437

cmd/artifact/list.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package artifact
22

33
import (
4-
"strings"
5-
64
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
75
"github.com/gildas/go-core"
6+
"github.com/gildas/go-flags"
87
"github.com/gildas/go-logger"
98
"github.com/spf13/cobra"
109
)
@@ -18,12 +17,20 @@ var listCmd = &cobra.Command{
1817

1918
var listOptions struct {
2019
Repository string
20+
Columns *flags.EnumSliceFlag
21+
SortBy *flags.EnumFlag
2122
}
2223

2324
func init() {
2425
Command.AddCommand(listCmd)
2526

27+
listOptions.Columns = flags.NewEnumSliceFlagWithAllAllowed(columns.Columns()...)
28+
listOptions.SortBy = flags.NewEnumFlag(columns.Sorters()...)
2629
listCmd.Flags().StringVar(&listOptions.Repository, "repository", "", "Repository to list artifacts from. Defaults to the current repository")
30+
listCmd.Flags().Var(listOptions.Columns, "columns", "Comma-separated list of columns to display")
31+
listCmd.Flags().Var(listOptions.SortBy, "sort", "Column to sort by")
32+
_ = listCmd.RegisterFlagCompletionFunc(listOptions.Columns.CompletionFunc("columns"))
33+
_ = listCmd.RegisterFlagCompletionFunc(listOptions.SortBy.CompletionFunc("sort"))
2734
}
2835

2936
func listProcess(cmd *cobra.Command, args []string) (err error) {
@@ -38,8 +45,6 @@ func listProcess(cmd *cobra.Command, args []string) (err error) {
3845
log.Infof("No artifact found")
3946
return nil
4047
}
41-
core.Sort(artifacts, func(a, b Artifact) bool {
42-
return strings.Compare(strings.ToLower(a.Name), strings.ToLower(b.Name)) == -1
43-
})
48+
core.Sort(artifacts, columns.SortBy(listOptions.SortBy.Value))
4449
return profile.Current.Print(cmd.Context(), cmd, Artifacts(artifacts))
4550
}

cmd/artifact/upload.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,15 @@ var uploadCmd = &cobra.Command{
2020
}
2121

2222
var uploadOptions struct {
23-
Repository string
24-
Progress bool
25-
StopOnError bool
26-
WarnOnError bool
27-
IgnoreErrors bool
23+
Repository string
24+
Progress bool
2825
}
2926

3027
func init() {
3128
Command.AddCommand(uploadCmd)
3229

3330
uploadCmd.Flags().StringVar(&uploadOptions.Repository, "repository", "", "Repository to upload artifacts to. Defaults to the current repository")
34-
uploadCmd.Flags().BoolVar(&uploadOptions.StopOnError, "stop-on-error", false, "Stop on error")
35-
uploadCmd.Flags().BoolVar(&uploadOptions.WarnOnError, "warn-on-error", false, "Warn on error")
36-
uploadCmd.Flags().BoolVar(&uploadOptions.IgnoreErrors, "ignore-errors", false, "Ignore errors")
3731
uploadCmd.Flags().BoolVar(&uploadOptions.Progress, "progress", false, "Show progress")
38-
uploadCmd.MarkFlagsMutuallyExclusive("stop-on-error", "warn-on-error", "ignore-errors")
3932
}
4033

4134
func uploadProcess(cmd *cobra.Command, args []string) error {

cmd/branch/branch.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package branch
22

33
import (
44
"fmt"
5+
"strings"
56

67
"bitbucket.org/gildas_cherruel/bb/cmd/commit"
78
"bitbucket.org/gildas_cherruel/bb/cmd/common"
9+
"github.com/gildas/go-core"
810
"github.com/gildas/go-errors"
911
"github.com/spf13/cobra"
1012
)
@@ -35,6 +37,24 @@ var Command = &cobra.Command{
3537
},
3638
}
3739

40+
var columns = common.Columns[Branch]{
41+
{Name: "name", DefaultSorter: true, Compare: func(a, b Branch) bool {
42+
return strings.Compare(strings.ToLower(a.Name), strings.ToLower(b.Name)) == -1
43+
}},
44+
{Name: "type", DefaultSorter: false, Compare: func(a, b Branch) bool {
45+
return strings.Compare(strings.ToLower(a.Type), strings.ToLower(b.Type)) == -1
46+
}},
47+
{Name: "target", DefaultSorter: false, Compare: func(a, b Branch) bool {
48+
return strings.Compare(strings.ToLower(a.Target.Hash), strings.ToLower(b.Target.Hash)) == -1
49+
}},
50+
{Name: "default_merge_strategy", DefaultSorter: false, Compare: func(a, b Branch) bool {
51+
return strings.Compare(strings.ToLower(a.DefaultMergeStrategy), strings.ToLower(b.DefaultMergeStrategy)) == -1
52+
}},
53+
{Name: "merge_strategies", DefaultSorter: false, Compare: func(a, b Branch) bool {
54+
return strings.Compare(strings.ToLower(strings.Join(a.MergeStrategies, ",")), strings.ToLower(strings.Join(b.MergeStrategies, ","))) == -1
55+
}},
56+
}
57+
3858
// NewReference creates a new BranchReference
3959
func NewReference(name string) *BranchReference {
4060
return &BranchReference{
@@ -43,18 +63,37 @@ func NewReference(name string) *BranchReference {
4363
}
4464
}
4565

46-
// GetHeader gets the header for a table
66+
// GetHeaders gets the header for a table
4767
//
4868
// implements common.Tableable
49-
func (branch Branch) GetHeader(short bool) []string {
69+
func (branch Branch) GetHeaders(cmd *cobra.Command) []string {
70+
if cmd != nil && cmd.Flag("columns") != nil && cmd.Flag("columns").Changed {
71+
if columns, err := cmd.Flags().GetStringSlice("columns"); err == nil {
72+
return core.Map(columns, func(column string) string { return strings.ReplaceAll(column, "_", " ") })
73+
}
74+
}
5075
return []string{"Name"}
5176
}
5277

5378
// GetRow gets the row for a table
5479
//
5580
// implements common.Tableable
5681
func (branch Branch) GetRow(headers []string) []string {
57-
return []string{branch.Name}
82+
var row []string
83+
84+
for _, header := range headers {
85+
switch strings.ToLower(header) {
86+
case "name":
87+
row = append(row, branch.Name)
88+
case "target":
89+
row = append(row, branch.Target.Hash)
90+
case "default_merge_strategy", "default merge strategy":
91+
row = append(row, branch.DefaultMergeStrategy)
92+
case "merge_strategies", "merge strategies":
93+
row = append(row, strings.Join(branch.MergeStrategies, ", "))
94+
}
95+
}
96+
return row
5897
}
5998

6099
// Validate validates a Branch

cmd/branch/branches.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111

1212
type Branches []Branch
1313

14-
// GetHeader gets the header for a table
14+
// GetHeaders gets the header for a table
1515
//
1616
// implements common.Tableables
17-
func (branches Branches) GetHeader() []string {
18-
return Branch{}.GetHeader(false)
17+
func (branches Branches) GetHeaders(cmd *cobra.Command) []string {
18+
return Branch{}.GetHeaders(cmd)
1919
}
2020

2121
// GetRowAt gets the row for a table

0 commit comments

Comments
 (0)