http-boot-config/config/cmd/config.go
2024-04-30 18:42:35 +02:00

60 lines
1.7 KiB
Go

/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"os"
"git.faercol.me/faercol/http-boot-config/config/config"
"github.com/spf13/cobra"
)
// configCmd represents the config command
var configCmd = &cobra.Command{
Use: "config",
Short: "Display the current configuration",
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) {
displayConfig()
},
}
func displayConfig() {
conf, err := config.Get()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get boot client configuration: %s\n", err.Error())
os.Exit(1)
}
if !conf.Enrolled {
fmt.Println("Boot service has not been configured yet.")
os.Exit(0)
}
fmt.Printf("- Client ID: %s\n", conf.ClientID.String())
fmt.Println("- Network config:")
fmt.Printf(" - Multicast group: %s\n", conf.Multicast.Group.String())
fmt.Printf(" - Multicast port: %d\n", conf.Multicast.Port)
fmt.Printf(" - Multicast source addr: %s\n", conf.Multicast.SrcAddr.String())
}
func init() {
rootCmd.AddCommand(configCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// configCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// configCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}