Skip to content

Commit

Permalink
Removing init() func
Browse files Browse the repository at this point in the history
  • Loading branch information
mogensen committed Apr 5, 2021
1 parent cb7408d commit b79f68f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ This results in a binary in `./bin/helm-changelog`.
$ ./bin/helm-changelog --help
Create changelogs for Helm Charts, based on git history

Usage:
helm-changelog [flags]

Flags:
-h, --help help for helm-changelog
-v, --verbosity string Log level (debug, info, warn, error, fatal, panic (default "warning")
Create changelogs for Helm Charts, based on git history

Usage:
helm-changelog [flags]

Expand Down
11 changes: 11 additions & 0 deletions cmd/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,16 @@ var rootCmd = &cobra.Command{
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
var v string

rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
if err := setUpLogs(os.Stdout, v); err != nil {
return err
}
return nil
}

rootCmd.PersistentFlags().StringVarP(&v, "verbosity", "v", logrus.WarnLevel.String(), "Log level (debug, info, warn, error, fatal, panic")

cobra.CheckErr(rootCmd.Execute())
}
21 changes: 0 additions & 21 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
package cmd

import (
"fmt"
"io"
"os"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func init() {
var v string

rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
if err := setUpLogs(os.Stdout, v); err != nil {
return err
}
return nil
}

rootCmd.PersistentFlags().StringVarP(&v, "verbosity", "v", logrus.WarnLevel.String(), "Log level (debug, info, warn, error, fatal, panic")

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
}

// setUpLogs set the log output ans the log level
func setUpLogs(out io.Writer, level string) error {
logrus.SetOutput(out)
Expand Down

0 comments on commit b79f68f

Please sign in to comment.