diff --git a/cmd/signerclient/main.go b/cmd/signerclient/main.go index 939d444..4358c56 100644 --- a/cmd/signerclient/main.go +++ b/cmd/signerclient/main.go @@ -18,9 +18,11 @@ limitations under the License. package main import ( + "bytes" "context" "flag" "fmt" + "io" "os" "strings" @@ -54,8 +56,6 @@ func main() { logger.SetOutput(os.Stdout) logger.SetLevel(logrus.InfoLevel) - logger.Infof("cacert-gosignerclient %s (%s) - build %s", version, commit, date) - flag.StringVar(&configFile, "config", defaultConfigFile, "signer client configuration file") flag.BoolVar(&showVersion, "version", false, "show version") flag.BoolVar(&verbose, "verbose", false, "verbose output") @@ -69,27 +69,31 @@ func main() { flag.Parse() - if showVersion { - return - } - parsedLevel, err := logrus.ParseLevel(logLevel) if err != nil { logger.WithError(err).Fatal("could not parse log level") } - logger.SetLevel(parsedLevel) - if generateConfig { if err = generateDefaultConfig(); err != nil { logger.WithError(err).Fatal("could not generate default configuration") } + os.Exit(1) + } + + logger.Infof("cacert-gosignerclient %s (%s) - build %s", version, commit, date) + + if showVersion { return } + logger.SetLevel(parsedLevel) + if err := startClient(configFile, logger); err != nil { logger.WithError(err).Fatal("client failure") + + os.Exit(1) } } @@ -100,18 +104,26 @@ serial: baud: 112500 ` - cfg, err := config.LoadConfiguration(strings.NewReader( - defaultBaseConfiguration)) + cfg, err := config.LoadConfiguration(strings.NewReader(defaultBaseConfiguration)) if err != nil { return fmt.Errorf("could not load empty configuration: %w", err) } - enc := yaml.NewEncoder(os.Stdout) + buf := &bytes.Buffer{} + + buf.WriteString("---\n") + + enc := yaml.NewEncoder(buf) if err = enc.Encode(cfg); err != nil { return fmt.Errorf("could not encode: %w", err) } + _, err = io.Copy(os.Stdout, buf) + if err != nil { + return fmt.Errorf("could not write output: %w", err) + } + return nil }