Skip to content

Commit

Permalink
Merged in release/0.10.2 (pull request #12)
Browse files Browse the repository at this point in the history
Merge release/0.10.2
  • Loading branch information
gildas committed Jun 14, 2024
2 parents a8b2fc0 + 0b0ff4e commit d03b3f2
Show file tree
Hide file tree
Showing 50 changed files with 259 additions and 220 deletions.
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ all: test build; ## Test and Build the application

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

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

archive: __archive_init__ __archive_all__ __archive_chocolatey__ __archive_debian__ __archive_rpm__ ; @ ## Archive the binaries
archive: __archive_init__ __archive_all__ __archive_chocolatey__ __archive_debian__ __archive_rpm__ __archive_snap__ ; @ ## Archive the binaries

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

Expand Down Expand Up @@ -211,7 +211,7 @@ __start__: stop $(BIN_DIR)/$(GOOS)/$(PROJECT) | $(TMP_DIR) $(LOG_DIR); $(info $(
$Q DEBUG=1 LOG_DESTINATION="$(LOG_DIR)/$(PROJECT).log" $(BIN_DIR)/$(GOOS)/$(PROJECT) & echo $$! > $(TMP_DIR)/$(PROJECT).pid

# publish recipes
.PHONY: __publish_init__ __publish_binaries__
.PHONY: __publish_init__ __publish_binaries__ __publish_snap__
__publish_init__:;
__publish_binaries__: archive
$(info $(M) Uploading the binary packages...)
Expand All @@ -223,6 +223,14 @@ __publish_binaries__: archive
$(info $(M) Uploading the RPM packages...)
$Q $(foreach archive, $(wildcard $(BIN_DIR)/*.rpm), go run . artifact upload --progress $(archive) ;)

__publish_snap__: \
$(TMP_DIR)/__publish_snap__ \
;

$(TMP_DIR)/__publish_snap__: $(TMP_DIR) __archive_snap__
$Q snapcraft upload --release=latest/edge $(BIN_DIR)/$(PACKAGE)_$(VERSION)_amd64.snap
$Q $(TOUCH)

# archive recipes
.PHONY: __archive_init__ __archive_all__ __archive_chocolatey__ __archive_debian__ __archive_rpm__ __archive_snap__
__archive_init__:; $(info $(M) Archiving binaries for application $(PROJECT))
Expand Down
3 changes: 2 additions & 1 deletion cmd/artifact/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
Expand Down Expand Up @@ -56,7 +57,7 @@ func deleteProcess(cmd *cobra.Command, args []string) error {

var merr errors.MultiError
for _, artifactName := range args {
if profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Deleting artifact %s", artifactName) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Deleting artifact %s", artifactName) {
err := profile.Current.Delete(
log.ToContext(cmd.Context()),
cmd,
Expand Down
3 changes: 2 additions & 1 deletion cmd/artifact/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
Expand Down Expand Up @@ -61,7 +62,7 @@ func getProcess(cmd *cobra.Command, args []string) error {

var merr errors.MultiError
for _, artifactName := range args {
if profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Downloading artifact %s to %s", artifactName, downloadOptions.Destination) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Downloading artifact %s to %s", artifactName, downloadOptions.Destination) {
err := profile.Current.Download(
log.ToContext(cmd.Context()),
cmd,
Expand Down
3 changes: 2 additions & 1 deletion cmd/artifact/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
Expand Down Expand Up @@ -46,7 +47,7 @@ func uploadProcess(cmd *cobra.Command, args []string) error {

var merr errors.MultiError
for _, artifactName := range args {
if profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Uploading artifact %s to %s", artifactName, downloadOptions.Destination) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Uploading artifact %s to %s", artifactName, downloadOptions.Destination) {
err := profile.Current.Upload(
log.ToContext(cmd.Context()),
cmd,
Expand Down
24 changes: 24 additions & 0 deletions cmd/common/whatif.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package common

import (
"context"
"fmt"
"os"

"github.com/gildas/go-logger"
"github.com/spf13/cobra"
)

// WhatIf prints what would be done by the command
//
// # If the DryRun flag is set, it prints what would be done by the command and tells the caller to not proceed
//
// otherwise it does nothing
func WhatIf(context context.Context, cmd *cobra.Command, format string, args ...any) (proceed bool) {
if cmd.Flag("dry-run").Changed {
logger.Must(logger.FromContext(context)).Infof("Dry run: "+format, args...)
fmt.Fprintf(os.Stderr, "Dry run: "+format+"\n", args...)
return false
}
return true
}
3 changes: 2 additions & 1 deletion cmd/issue/attachment/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-flags"
Expand Down Expand Up @@ -62,7 +63,7 @@ func deleteProcess(cmd *cobra.Command, args []string) error {

var merr errors.MultiError
for _, attachmentID := range args {
if profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Deleting attachment %s from issue %s", attachmentID, deleteOptions.IssueID) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Deleting attachment %s from issue %s", attachmentID, deleteOptions.IssueID) {
err := profile.Current.Delete(
log.ToContext(cmd.Context()),
cmd,
Expand Down
3 changes: 2 additions & 1 deletion cmd/issue/attachment/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-flags"
Expand Down Expand Up @@ -58,7 +59,7 @@ func downloadProcess(cmd *cobra.Command, args []string) error {
return errors.ArgumentMissing.With("profile")
}

if profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Downloading attachment %s from issue %s to %s", args[0], downloadOptions.IssueID, downloadOptions.Destination) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Downloading attachment %s from issue %s to %s", args[0], downloadOptions.IssueID, downloadOptions.Destination) {
err := profile.Current.Download(
log.ToContext(cmd.Context()),
cmd,
Expand Down
3 changes: 2 additions & 1 deletion cmd/issue/attachment/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-flags"
Expand Down Expand Up @@ -43,7 +44,7 @@ func uploadProcess(cmd *cobra.Command, args []string) error {
return errors.ArgumentMissing.With("profile")
}

if profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Uploading attachment %s to issue %s", args[0], uploadOptions.IssueID) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Uploading attachment %s to issue %s", args[0], uploadOptions.IssueID) {
err := profile.Current.Upload(
log.ToContext(cmd.Context()),
cmd,
Expand Down
2 changes: 1 addition & 1 deletion cmd/issue/comment/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func createProcess(cmd *cobra.Command, args []string) (err error) {
}

log.Record("payload", payload).Infof("Creating issue comment")
if !profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Creating comment for issue %s", createOptions.IssueID) {
if !common.WhatIf(log.ToContext(cmd.Context()), cmd, "Creating comment for issue %s", createOptions.IssueID) {
return nil
}
var comment Comment
Expand Down
3 changes: 2 additions & 1 deletion cmd/issue/comment/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-flags"
Expand Down Expand Up @@ -61,7 +62,7 @@ func deleteProcess(cmd *cobra.Command, args []string) error {

var merr errors.MultiError
for _, commentID := range args {
if profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Deleting comment %s from issue %s", commentID, deleteOptions.IssueID) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Deleting comment %s from issue %s", commentID, deleteOptions.IssueID) {
err := profile.Current.Delete(
log.ToContext(cmd.Context()),
cmd,
Expand Down
2 changes: 1 addition & 1 deletion cmd/issue/comment/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func updateProcess(cmd *cobra.Command, args []string) (err error) {
}

log.Record("payload", payload).Infof("Updating issue comment")
if !profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Updating comment %s for issue %s", updateOptions.Comment, updateOptions.IssueID) {
if !common.WhatIf(log.ToContext(cmd.Context()), cmd, "Updating comment %s for issue %s", updateOptions.Comment, updateOptions.IssueID) {
return nil
}
var comment Comment
Expand Down
2 changes: 1 addition & 1 deletion cmd/issue/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func createProcess(cmd *cobra.Command, args []string) (err error) {
}

log.Record("payload", payload).Infof("Creating issue")
if !profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Creating issue") {
if !common.WhatIf(log.ToContext(cmd.Context()), cmd, "Creating issue") {
return nil
}
var issue Issue
Expand Down
3 changes: 2 additions & 1 deletion cmd/issue/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
Expand Down Expand Up @@ -56,7 +57,7 @@ func deleteProcess(cmd *cobra.Command, args []string) error {

var merr errors.MultiError
for _, issueID := range args {
if profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Deleting issue %s", issueID) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Deleting issue %s", issueID) {
err := profile.Current.Delete(
log.ToContext(cmd.Context()),
cmd,
Expand Down
3 changes: 2 additions & 1 deletion cmd/issue/unvote.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
Expand Down Expand Up @@ -46,7 +47,7 @@ func unvoteProcess(cmd *cobra.Command, args []string) (err error) {
return errors.ArgumentMissing.With("profile")
}

if profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Unvoting from issue %s", args[0]) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Unvoting from issue %s", args[0]) {
err = profile.Current.Delete(
log.ToContext(cmd.Context()),
cmd,
Expand Down
3 changes: 2 additions & 1 deletion cmd/issue/unwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
Expand Down Expand Up @@ -46,7 +47,7 @@ func unwatchProcess(cmd *cobra.Command, args []string) (err error) {
return errors.ArgumentMissing.With("profile")
}

if profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Unwatching issue %s", args[0]) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Unwatching issue %s", args[0]) {
err = profile.Current.Delete(
log.ToContext(cmd.Context()),
cmd,
Expand Down
2 changes: 1 addition & 1 deletion cmd/issue/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func updateProcess(cmd *cobra.Command, args []string) (err error) {
log.Record("payload", payload).Infof("Updating issue %s", args[0])
var issue Issue

if profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Updating issue %s", args[0]) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Updating issue %s", args[0]) {
err = profile.Current.Put(
log.ToContext(cmd.Context()),
cmd,
Expand Down
3 changes: 2 additions & 1 deletion cmd/issue/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
Expand Down Expand Up @@ -46,7 +47,7 @@ func voteProcess(cmd *cobra.Command, args []string) (err error) {
return errors.ArgumentMissing.With("profile")
}

if profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Voting for issue %s", args[0]) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Voting for issue %s", args[0]) {
err = profile.Current.Put(
log.ToContext(cmd.Context()),
cmd,
Expand Down
3 changes: 2 additions & 1 deletion cmd/issue/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
Expand Down Expand Up @@ -58,7 +59,7 @@ func watchProcess(cmd *cobra.Command, args []string) (err error) {
return
}

if profile.Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Watching issue %s", args[0]) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Watching issue %s", args[0]) {
err = profile.Current.Put(
log.ToContext(cmd.Context()),
cmd,
Expand Down
3 changes: 2 additions & 1 deletion cmd/profile/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"
"path/filepath"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"github.com/gildas/go-errors"
"github.com/gildas/go-flags"
"github.com/gildas/go-logger"
Expand Down Expand Up @@ -73,7 +74,7 @@ func createProcess(cmd *cobra.Command, args []string) error {
return errors.DuplicateFound.With("name", createOptions.Name)
}

if !Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Creating profile %s", createOptions.Name) {
if !common.WhatIf(log.ToContext(cmd.Context()), cmd, "Creating profile %s", createOptions.Name) {
return nil
}
Profiles.Add(&createOptions.Profile)
Expand Down
5 changes: 3 additions & 2 deletions cmd/profile/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package profile
import (
"strings"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"github.com/gildas/go-logger"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -40,11 +41,11 @@ func deleteProcess(cmd *cobra.Command, args []string) (err error) {

if deleteOptions.All {
log.Infof("Deleting all profiles")
if Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Deleting all profiles") {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Deleting all profiles") {
deleted = Profiles.Delete(Profiles.Names()...)
}
} else {
if Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Deleting profiles %s", strings.Join(args, ", ")) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Deleting profiles %s", strings.Join(args, ", ")) {
deleted = Profiles.Delete(args...)
}
}
Expand Down
13 changes: 0 additions & 13 deletions cmd/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,19 +287,6 @@ func (profile Profile) Print(context context.Context, cmd *cobra.Command, payloa
return nil
}

// WhatIf prints what would be done by the command
//
// If the DryRun flag is set, it prints what would be done by the command
// otherwise it does nothing
func (profile Profile) WhatIf(context context.Context, cmd *cobra.Command, format string, args ...any) (proceed bool) {
if cmd.Flag("dry-run").Changed {
logger.Must(logger.FromContext(context)).Infof("Dry run: "+format, args...)
fmt.Fprintf(os.Stderr, "Dry run: "+format+"\n", args...)
return false
}
return true
}

// MarshalJSON marshals this profile to JSON
//
// implements json.Marshaler
Expand Down
3 changes: 2 additions & 1 deletion cmd/profile/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"
"path/filepath"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"github.com/gildas/go-errors"
"github.com/gildas/go-flags"
"github.com/gildas/go-logger"
Expand Down Expand Up @@ -74,7 +75,7 @@ func updateProcess(cmd *cobra.Command, args []string) error {
}

log.Record("profile", profile).Debugf("Updating profile %s", profile.Name)
if !Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Updating profile %s", profile.Name) {
if !common.WhatIf(log.ToContext(cmd.Context()), cmd, "Updating profile %s", profile.Name) {
return nil
}
err := profile.Update(updateOptions.Profile)
Expand Down
3 changes: 2 additions & 1 deletion cmd/profile/use.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package profile

import (
"bitbucket.org/gildas_cherruel/bb/cmd/common"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -28,7 +29,7 @@ func useProcess(cmd *cobra.Command, args []string) error {
if !found {
return errors.NotFound.With("profile", args[0])
}
if Current.WhatIf(log.ToContext(cmd.Context()), cmd, "Using profile %s as default", args[0]) {
if common.WhatIf(log.ToContext(cmd.Context()), cmd, "Using profile %s as default", args[0]) {
Profiles.SetCurrent(profile.Name)
viper.Set("profiles", Profiles)
return viper.WriteConfig()
Expand Down
Loading

0 comments on commit d03b3f2

Please sign in to comment.