Skip to content

Commit

Permalink
Remove redunant logs
Browse files Browse the repository at this point in the history
Since the Cobra framework logs errors of commands already, they don't
need to be logged again in `main.go`.

Signed-off-by: Simon Rüegg <simon@rueggs.ch>
  • Loading branch information
srueg committed Mar 31, 2020
1 parent 5b46477 commit befe3c3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
14 changes: 9 additions & 5 deletions cmd/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

"github.com/appuio/seiso/cfg"
"github.com/appuio/seiso/pkg/cleanup"
"github.com/appuio/seiso/pkg/git"
Expand All @@ -12,13 +13,15 @@ import (

var (
historyCmd = &cobra.Command{
Use: "history [IMAGE]",
Aliases: []string{"hist"},
Short: "Clean up excessive image tags",
Long: `Clean up excessive image tags matching the commit hashes (prefix) of the git repository`,
Args: cobra.MinimumNArgs(1),
Use: "history [PROJECT/IMAGE]",
Aliases: []string{"hist"},
Short: "Clean up excessive image tags",
Long: `Clean up excessive image tags matching the commit hashes (prefix) of the git repository`,
Args: cobra.ExactArgs(1),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := validateHistoryCommandInput(args); err != nil {
cmd.Usage()
return err
}
return ExecuteHistoryCleanupCommand(args)
Expand Down Expand Up @@ -46,6 +49,7 @@ func validateHistoryCommandInput(args []string) error {
return nil
}

// ExecuteHistoryCleanupCommand executes the history cleanup command
func ExecuteHistoryCleanupCommand(args []string) error {

c := config.History
Expand Down
20 changes: 12 additions & 8 deletions cmd/orphans.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package cmd
import (
"errors"
"fmt"
"regexp"
"strings"
"time"

"github.com/appuio/seiso/cfg"
"github.com/appuio/seiso/pkg/cleanup"
"github.com/appuio/seiso/pkg/git"
"github.com/appuio/seiso/pkg/openshift"
"github.com/karrick/tparse"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"regexp"
"strings"
"time"
)

const (
Expand All @@ -26,13 +27,15 @@ var (
// orphanCmd represents a cobra command to clean up images by comparing the git commit history. It removes any
// image tags that are not found in the git history by given criteria.
orphanCmd = &cobra.Command{
Use: "orphans [IMAGE]",
Short: "Clean up unknown image tags",
Long: orphanCommandLongDescription,
Aliases: []string{"orph"},
Args: cobra.MinimumNArgs(1),
Use: "orphans [PROJECT/IMAGE]",
Short: "Clean up unknown image tags",
Long: orphanCommandLongDescription,
Aliases: []string{"orph"},
Args: cobra.ExactArgs(1),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := validateOrphanCommandInput(args); err != nil {
cmd.Usage()
return err
}
return ExecuteOrphanCleanupCommand(args)
Expand Down Expand Up @@ -71,6 +74,7 @@ func validateOrphanCommandInput(args []string) error {
return nil
}

// ExecuteOrphanCleanupCommand executes the orphan cleanup command
func ExecuteOrphanCleanupCommand(args []string) error {

o := config.Orphan
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
// rootCmd represents the base command when called without any subcommands
rootCmd = &cobra.Command{
Use: "seiso",
Short: "keeps your kubernetes projects clean",
Short: "Keeps your Kubernetes projects clean",
PersistentPreRun: parseConfig,
}
config = cfg.NewDefaultConfig()
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package main

import (
"fmt"
"os"

"github.com/appuio/seiso/cmd"
log "github.com/sirupsen/logrus"
)

var (
Expand All @@ -16,6 +16,6 @@ var (
func main() {
cmd.SetVersion(fmt.Sprintf("%s, commit %s, date %s", version, commit, date))
if err := cmd.Execute(); err != nil {
log.WithError(err).Fatal("Command aborted.")
os.Exit(1)
}
}

0 comments on commit befe3c3

Please sign in to comment.