Add password parameter

This commit is contained in:
raul 2024-05-13 12:02:03 +02:00
parent a615cb9194
commit 8cb40303dc
1 changed files with 8 additions and 0 deletions

View File

@ -31,6 +31,7 @@ func init() {
rootCmd.AddCommand(serverCmd) rootCmd.AddCommand(serverCmd)
serverCmd.PersistentFlags().StringP("port", "p", "1302", "port to use for listening") serverCmd.PersistentFlags().StringP("port", "p", "1302", "port to use for listening")
serverCmd.PersistentFlags().StringP("history", "r", "", "File to store and recover chat history from") serverCmd.PersistentFlags().StringP("history", "r", "", "File to store and recover chat history from")
serverCmd.PersistentFlags().String("password", "", "Password for accessing the chat server")
} }
func setServerParameters(cmd *cobra.Command) error { func setServerParameters(cmd *cobra.Command) error {
@ -49,5 +50,12 @@ func setServerParameters(cmd *cobra.Command) error {
logLocation = parameterHistory logLocation = parameterHistory
isLogging = true isLogging = true
} }
parPassword, err := cmd.Flags().GetString("password")
if err != nil {
return err
}
if parPassword != "" {
password = parPassword
}
return nil return nil
} }