/* Copyright © 2024 raul */ package cmd import ( "github.com/spf13/cobra" "log" ) // serveCmd represents the serve command var serveCmd = &cobra.Command{ Use: "server", Short: "Start HTTP server", Long: `Start HTTP server`, Run: func(cmd *cobra.Command, args []string) { if err := setServerParameters(cmd); err != nil { log.Fatalf("Error happened trying to set parameters: %v\n", err) } server() }, } func init() { rootCmd.AddCommand(serveCmd) serveCmd.PersistentFlags().StringP("port", "p", "1302", "Port for server to listen on") } func setServerParameters(cmd *cobra.Command) error { parameterPort, err := cmd.Flags().GetString("port") if err != nil { return err } if parameterPort != "" { listenPort = parameterPort } return nil }