58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
/*
|
|
Copyright © 2024 Raul <raul@bulgariu.xyz>
|
|
*/
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// serverCmd represents the server command
|
|
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 := setParameters(cmd); err != nil {
|
|
log.Fatalln("Error: Port could not be read!")
|
|
}
|
|
|
|
Server()
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(serverCmd)
|
|
|
|
// Here you will define your flags and configuration settings.
|
|
|
|
// Cobra supports Persistent Flags which will work for this command
|
|
// and all subcommands, e.g.:
|
|
// serverCmd.PersistentFlags().String("foo", "", "A help for foo")
|
|
serverCmd.PersistentFlags().String("port", "1302", "port to use for listening")
|
|
|
|
// Cobra supports local flags which will only run when this command
|
|
// is called directly, e.g.:
|
|
// serverCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
|
}
|
|
|
|
func setParameters(cmd *cobra.Command) error {
|
|
parameterPort, err := cmd.Flags().GetString("port")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if parameterPort != "" {
|
|
port = parameterPort
|
|
}
|
|
return nil
|
|
}
|