/* Copyright © 2024 raul */ package cmd import ( "github.com/spf13/cobra" "log" ) var serverCmd = &cobra.Command{ Use: "server", Short: "A brief description of your command", Long: `A longer description that spans multiple lines and likely contains examples and usage of using your command. For example: Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { if err := setServerParameters(cmd); err != nil { log.Fatalf("Error happened trying to set parameters: %v\n", err) } }, } func init() { rootCmd.AddCommand(serverCmd) serverCmd.PersistentFlags().StringP("port", "p", "1302", "port to use for listening") } func setServerParameters(cmd *cobra.Command) error { parameterPort, err := cmd.Flags().GetString("port") if err != nil { return err } if parameterPort != "" { listenPort = parameterPort } return nil }