Main project #1
33
cmd/root.go
33
cmd/root.go
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
|
Copyright © 2024 raul <raul@bulgariu.xyz>
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -10,25 +10,14 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// rootCmd represents the base command when called without any subcommands
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "aemet",
|
Use: "aemet",
|
||||||
Short: "A brief description of your application",
|
Short: "API Server that fetches spanish weather data from the AEMET",
|
||||||
Long: `A longer description that spans multiple lines and likely contains
|
Long: `API Server that fetches spanish weather data from the AEMET formatted
|
||||||
examples and usage of using your application. For example:
|
in XML and translates it to JSON, optionally allowing to render the
|
||||||
|
obtained data in a web page.`,
|
||||||
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.`,
|
|
||||||
// Uncomment the following line if your bare application
|
|
||||||
// has an action associated with it:
|
|
||||||
// Run: func(cmd *cobra.Command, args []string) { },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
|
||||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
err := rootCmd.Execute()
|
err := rootCmd.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -37,15 +26,5 @@ func Execute() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Here you will define your flags and configuration settings.
|
|
||||||
// Cobra supports persistent flags, which, if defined here,
|
|
||||||
// will be global for your application.
|
|
||||||
|
|
||||||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.aemet.yaml)")
|
|
||||||
|
|
||||||
// Cobra also supports local flags, which will only run
|
|
||||||
// when this action is called directly.
|
|
||||||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,8 @@ import (
|
||||||
|
|
||||||
var serverCmd = &cobra.Command{
|
var serverCmd = &cobra.Command{
|
||||||
Use: "server",
|
Use: "server",
|
||||||
Short: "A brief description of your command",
|
Short: "Start aemet webserver",
|
||||||
Long: `A longer description that spans multiple lines and likely contains examples
|
Long: `Start aemet webserver`,
|
||||||
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) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if err := setServerParameters(cmd); err != nil {
|
if err := setServerParameters(cmd); err != nil {
|
||||||
log.Fatalf("Error happened trying to set parameters: %v\n", err)
|
log.Fatalf("Error happened trying to set parameters: %v\n", err)
|
||||||
|
@ -28,7 +23,7 @@ to quickly create a Cobra application.`,
|
||||||
|
|
||||||
func init() {
|
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")
|
||||||
}
|
}
|
||||||
|
|
||||||
func setServerParameters(cmd *cobra.Command) error {
|
func setServerParameters(cmd *cobra.Command) error {
|
||||||
|
|
Loading…
Reference in New Issue