diff --git a/.golangci.yml b/.golangci.yml index d9704de..701dd4f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -74,35 +74,9 @@ run: # output configuration options output: - # Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions - # - # Multiple can be specified by separating them by comma, output can be provided - # for each of them by separating format name and path by colon symbol. - # Output path can be either `stdout`, `stderr` or path to the file to write to. - # Example: "checkstyle:report.json,colored-line-number" - # - # Default: colored-line-number - # format: json - - # Print lines of code with issue. - # Default: true - # print-issued-lines: false - - # Print linter name in the end of issue text. - # Default: true - # print-linter-name: false - - # Make issues output unique by line. - # Default: true - # uniq-by-line: false - - # Add a prefix to the output file references. - # Default is no prefix. - # path-prefix: "" - - # Sort results by: filepath, line and column. - # sort-results: true - + formats: + - format: colored-line-number + path: stderr # All available settings of specific linters. linters-settings: @@ -148,14 +122,11 @@ linters: # Disable specific linter # https://golangci-lint.run/usage/linters/#disabled-by-default disable: - - contextcheck - cyclop - depguard - dupl - err113 - - exhaustive - exhaustruct - - exportloopref - forcetypeassert - funlen - gci @@ -163,15 +134,11 @@ linters: - gocognit - goconst - ireturn - - inamedparam - lll - mnd - - musttag - - nestif - - nilnil - nlreturn - perfsprint - - promlinter + - tenv - varnamelen - wrapcheck - wsl diff --git a/main.go b/main.go index 46953a0..720adaa 100644 --- a/main.go +++ b/main.go @@ -76,9 +76,13 @@ var ReleaseVersion = "1.2.1-rc.1" func main() { ctx, cancel := context.WithCancel(context.Background()) - if err := fetchConfig(); err != nil { + exit, err := fetchConfig() + if err != nil { zerologger.Fatal().Err(err).Msg("Failed to fetch configuration") } + if exit { + os.Exit(0) + } majordomoSvc, err := util.InitMajordomo(ctx) if err != nil { @@ -155,7 +159,8 @@ func main() { } // fetchConfig fetches configuration from various sources. -func fetchConfig() error { +// If this returns true then the calling code should exit. +func fetchConfig() (bool, error) { pflag.String("base-dir", "", "base directory for configuration files") pflag.String("log-level", "info", "minimum level of messsages to log") pflag.String("log-file", "", "redirect log output to a file") @@ -170,7 +175,12 @@ func fetchConfig() error { pflag.String("slashing-protection-file", "", "location of slashing protection file for import or export") pflag.Parse() if err := viper.BindPFlags(pflag.CommandLine); err != nil { - return errors.Wrap(err, "failed to bind pflags to viper") + return false, errors.Wrap(err, "failed to bind pflags to viper") + } + + if viper.GetBool("version") { + fmt.Fprintf(os.Stdout, "%s\n", ReleaseVersion) + return true, nil } if viper.GetString("base-dir") != "" { @@ -181,7 +191,7 @@ func fetchConfig() error { // Home directory. home, err := homedir.Dir() if err != nil { - return errors.Wrap(err, "failed to obtain home directory") + return false, errors.Wrap(err, "failed to obtain home directory") } viper.AddConfigPath(home) viper.SetConfigName(".dirk") @@ -206,16 +216,16 @@ func fetchConfig() error { // get very far anyway. if viper.GetString("server.name") == "" { // Assume the underlying issue is that the configuration file is missing. - return errors.Wrap(err, "could not find the configuration file") + return false, errors.Wrap(err, "could not find the configuration file") } case errors.As(err, &viper.ConfigParseError{}): - return errors.Wrap(err, "could not parse the configuration file") + return false, errors.Wrap(err, "could not parse the configuration file") default: - return errors.Wrap(err, "failed to obtain configuration") + return false, errors.Wrap(err, "failed to obtain configuration") } } - return nil + return false, nil } // initProfiling initialises the profiling server. @@ -237,11 +247,6 @@ func initProfiling() { } func runCommands(ctx context.Context, majordomoSvc majordomo.Service) (bool, int) { - if viper.GetBool("version") { - fmt.Fprintf(os.Stdout, "%s\n", ReleaseVersion) - return true, 0 - } - if viper.GetBool("show-certificates") { err := cmd.ShowCertificates(ctx, majordomoSvc) if err != nil {