49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
/*
|
|
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
|
|
*/
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/server"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
// serverCmd represents the server command
|
|
var serverCmd = &cobra.Command{
|
|
Use: "server",
|
|
Short: "Start the http server",
|
|
Long: ``,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
if err := viper.BindPFlag("debug", cmd.Flags().Lookup("debug")); err != nil {
|
|
fmt.Println("Unable to bind flag:", err)
|
|
}
|
|
if err := viper.BindPFlag("port", cmd.Flags().Lookup("port")); err != nil {
|
|
fmt.Println("Unable to bind flag:", err)
|
|
}
|
|
|
|
logger.Println("starting http server...")
|
|
server.StartServer(logger, viper.GetInt("port"))
|
|
},
|
|
}
|
|
|
|
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")
|
|
|
|
// 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")
|
|
serverCmd.Flags().BoolP("debug", "d", false, "Enable debugging")
|
|
serverCmd.Flags().IntP("port", "p", 4242, "The port to listen on")
|
|
}
|