44 "fmt"
55 "os"
66 "path/filepath"
7+ "runtime"
78 "time"
89
910 "github.com/pterm/pterm"
@@ -65,6 +66,8 @@ func init() {
6566 rootCmd .PersistentFlags ().String ("tlsClientPrivateKey" , "" , "Client private key for mtls" )
6667 rootCmd .PersistentFlags ().String ("tlsClientCert" , "" , "Client certificate for mtls" )
6768
69+ rootCmd .PersistentFlags ().Uint ("workers" , 0 , "Number of Concurrent Workers for Expensive Operations. 0 (default) uses the number of CPU cores" )
70+
6871 viper .BindPFlag ("debug" , rootCmd .PersistentFlags ().Lookup ("debug" ))
6972 viper .BindPFlag ("timeout" , rootCmd .PersistentFlags ().Lookup ("timeout" ))
7073 viper .BindPFlag ("serverAddress" , rootCmd .PersistentFlags ().Lookup ("serverAddress" ))
@@ -81,6 +84,8 @@ func init() {
8184 viper .BindPFlag ("tlsSkipVerify" , rootCmd .PersistentFlags ().Lookup ("tlsSkipVerify" ))
8285 viper .BindPFlag ("tlsClientCert" , rootCmd .PersistentFlags ().Lookup ("tlsClientCert" ))
8386 viper .BindPFlag ("tlsClientPrivateKey" , rootCmd .PersistentFlags ().Lookup ("tlsClientPrivateKey" ))
87+
88+ viper .BindPFlag ("workers" , rootCmd .PersistentFlags ().Lookup ("workers" ))
8489}
8590
8691func fileToContent (file , contentFlag string ) {
@@ -148,6 +153,15 @@ func initConfig() {
148153 } else if err != nil && viper .GetBool ("debug" ) {
149154 fmt .Fprintln (os .Stderr , "Getting Client Certificate File Flag:" , err )
150155 }
156+
157+ // If Workers is set to 0, autodetect Number of Cores
158+ workers := viper .GetUint ("workers" )
159+ if workers == 0 {
160+ viper .Set ("workers" , runtime .NumCPU ())
161+ if viper .GetBool ("debug" ) {
162+ fmt .Fprintln (os .Stderr , "Autodetected Worker Count:" , viper .GetUint ("workers" ))
163+ }
164+ }
151165}
152166
153167func SetVersionInfo (version , commit , date string , dirty bool ) {
0 commit comments