Skip to content
Snippets Groups Projects
Commit 7d12dff1 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Basic logging and command line options

parent 175c8ede
No related branches found
No related tags found
No related merge requests found
...@@ -172,12 +172,13 @@ var rootCmd = &cobra.Command{ ...@@ -172,12 +172,13 @@ var rootCmd = &cobra.Command{
Short: "Runs a client for cMix anonymous communication platform", Short: "Runs a client for cMix anonymous communication platform",
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if !verbose && viper.Get("verbose") != nil { initLog(viper.GetBool("verbose"), viper.GetString("log"))
verbose = viper.GetBool("verbose") jww.INFO.Printf(Version())
} },
if logPath == "" && viper.Get("logPath") != nil {
logPath = viper.GetString("logPath")
} }
func initLog(verbose bool, logPath string) {
if logPath != "-" && logPath != "" {
// Disable stdout output // Disable stdout output
jww.SetStdoutOutput(ioutil.Discard) jww.SetStdoutOutput(ioutil.Discard)
// Use log file // Use log file
...@@ -187,10 +188,16 @@ var rootCmd = &cobra.Command{ ...@@ -187,10 +188,16 @@ var rootCmd = &cobra.Command{
panic(err.Error()) panic(err.Error())
} }
jww.SetLogOutput(logOutput) jww.SetLogOutput(logOutput)
}
if verbose { if verbose {
jww.SetStdoutThreshold(jww.LevelTrace)
jww.SetLogThreshold(jww.LevelTrace) jww.SetLogThreshold(jww.LevelTrace)
} else {
jww.SetStdoutThreshold(jww.LevelInfo)
jww.SetLogThreshold(jww.LevelInfo)
} }
},
} }
func isValidUser(usr []byte) (bool, *id.ID) { func isValidUser(usr []byte) (bool, *id.ID) {
...@@ -222,60 +229,26 @@ func init() { ...@@ -222,60 +229,26 @@ func init() {
// Here you will define your flags and configuration settings. // Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here, // Cobra supports persistent flags, which, if defined here,
// will be global for your application. // will be global for your application.
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, rootCmd.Flags().BoolP("verbose", "v", false,
"Verbose mode for debugging") "Verbose mode for debugging")
viper.BindPFlag("verbose", rootCmd.Flags().Lookup("verbose"))
rootCmd.PersistentFlags().BoolVarP(&noBlockingTransmission, "noBlockingTransmission", rootCmd.Flags().StringP("session", "s",
"", false, "Sets if transmitting messages blocks or not. "+ "", "Sets the initial username and the directory for "+
"Defaults to true if unset.") "client storage")
rootCmd.PersistentFlags().Uint32VarP(&rateLimiting, "rateLimiting", "", viper.BindPFlag("session", rootCmd.Flags().Lookup("session"))
1000, "Sets the amount of time, in ms, "+
"that the client waits between sending messages. "+
"set to zero to disable. "+
"Automatically disabled if 'blockingTransmission' is false")
rootCmd.PersistentFlags().Uint64VarP(&userId, "userid", "i", 0,
"ID to sign in as. Does not register, must be an available precanned user")
rootCmd.PersistentFlags().StringVarP(&registrationCode,
"regcode", "r",
"",
"Registration Code with the registration server")
rootCmd.PersistentFlags().StringVarP(&username,
"username", "E",
"",
"Username to register for User Discovery")
rootCmd.PersistentFlags().StringVarP(&sessionFile, "sessionfile", "f",
"", "Passes a file path for loading a session. "+
"If the file doesn't exist the code will register the user and"+
" store it there. If not passed the session will be stored"+
" to ram and lost when the cli finishes")
rootCmd.PersistentFlags().StringVarP(&ndfPubKey,
"ndfPubKeyCertPath",
"p",
"",
"Path to the certificated containing the public key for the "+
" network definition JSON file")
rootCmd.PersistentFlags().StringVarP(&ndfPath,
"ndf",
"n",
"ndf.json",
"Path to the network definition JSON file")
rootCmd.PersistentFlags().BoolVar(&skipNDFVerification,
"skipNDFVerification",
false,
"Specifies if the NDF should be loaded without the signature")
rootCmd.PersistentFlags().StringVarP(&sessFilePassword, rootCmd.Flags().StringP("password", "p", "",
"password",
"P",
"",
"Password to the session file") "Password to the session file")
viper.BindPFlag("password", rootCmd.Flags().Lookup("password"))
rootCmd.Flags().StringP("ndf", "n", "ndf.json",
"Path to the network definition JSON file")
viper.BindPFlag("ndf", rootCmd.Flags().Lookup("ndf"))
rootCmd.Flags().StringP("log", "l", "-",
"Path to the log output path (- is stdout)")
viper.BindPFlag("log", rootCmd.Flags().Lookup("log"))
// Cobra also supports local flags, which will only run // Cobra also supports local flags, which will only run
// when this action is called directly. // when this action is called directly.
...@@ -307,11 +280,8 @@ func init() { ...@@ -307,11 +280,8 @@ func init() {
"w", 1, "Denotes the number of messages the "+ "w", 1, "Denotes the number of messages the "+
"client should receive before closing") "client should receive before closing")
rootCmd.Flags().StringVarP(&searchForUser, "SearchForUser", "s", "", // rootCmd.Flags().StringVarP(&searchForUser, "SearchForUser", "s", "",
"Sets the email to search for to find a user with user discovery") // "Sets the email to search for to find a user with user discovery")
rootCmd.Flags().StringVarP(&logPath, "log", "l", "",
"Print logs to specified log file, not stdout")
rootCmd.Flags().UintVarP(&messageTimeout, "messageTimeout", rootCmd.Flags().UintVarP(&messageTimeout, "messageTimeout",
"t", 45, "The number of seconds to wait for "+ "t", 45, "The number of seconds to wait for "+
......
...@@ -18,9 +18,11 @@ import ( ...@@ -18,9 +18,11 @@ import (
// Change this value to set the version for this build // Change this value to set the version for this build
const currentVersion = "1.4.0" const currentVersion = "1.4.0"
func printVersion() { func Version() string {
fmt.Printf("Elixxir Client v%s -- %s\n\n", api.SEMVER, api.GITVERSION) out := fmt.Sprintf("Elixxir Client v%s -- %s\n\n", api.SEMVER,
fmt.Printf("Dependencies:\n\n%s\n", api.DEPENDENCIES) api.GITVERSION)
out += fmt.Sprintf("Dependencies:\n\n%s\n", api.DEPENDENCIES)
return out
} }
func init() { func init() {
...@@ -33,7 +35,7 @@ var versionCmd = &cobra.Command{ ...@@ -33,7 +35,7 @@ var versionCmd = &cobra.Command{
Short: "Print the version and dependency information for the Elixxir binary", Short: "Print the version and dependency information for the Elixxir binary",
Long: `Print the version and dependency information for the Elixxir binary`, Long: `Print the version and dependency information for the Elixxir binary`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
printVersion() fmt.Printf(Version())
}, },
} }
......
...@@ -6,15 +6,17 @@ require ( ...@@ -6,15 +6,17 @@ require (
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/golang/protobuf v1.4.2 github.com/golang/protobuf v1.4.2
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/pelletier/go-toml v1.6.0 // indirect github.com/magiconair/properties v1.8.4 // indirect
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/smartystreets/assertions v1.0.1 // indirect github.com/smartystreets/assertions v1.0.1 // indirect
github.com/spf13/afero v1.2.2 // indirect github.com/spf13/afero v1.4.0 // indirect
github.com/spf13/cast v1.3.1 // indirect github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.0.0 github.com/spf13/cobra v1.0.0
github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.6.2 github.com/spf13/viper v1.7.1
gitlab.com/elixxir/comms v0.0.0-20200924172854-724244a10032 gitlab.com/elixxir/comms v0.0.0-20200924172854-724244a10032
gitlab.com/elixxir/crypto v0.0.0-20200921195205-bca0178268ec gitlab.com/elixxir/crypto v0.0.0-20200921195205-bca0178268ec
gitlab.com/elixxir/ekv v0.1.1 gitlab.com/elixxir/ekv v0.1.1
...@@ -23,9 +25,9 @@ require ( ...@@ -23,9 +25,9 @@ require (
gitlab.com/xx_network/crypto v0.0.0-20200812183430-c77a5281c686 gitlab.com/xx_network/crypto v0.0.0-20200812183430-c77a5281c686
gitlab.com/xx_network/primitives v0.0.0-20200915204206-eb0287ed0031 gitlab.com/xx_network/primitives v0.0.0-20200915204206-eb0287ed0031
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
golang.org/x/sys v0.0.0-20200828194041-157a740278f4 // indirect golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d // indirect
google.golang.org/protobuf v1.25.0 google.golang.org/protobuf v1.25.0
gopkg.in/ini.v1 v1.52.0 // indirect gopkg.in/ini.v1 v1.61.0 // indirect
) )
replace google.golang.org/grpc => github.com/grpc/grpc-go v1.27.1 replace google.golang.org/grpc => github.com/grpc/grpc-go v1.27.1
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment