update.go 687 B

1234567891011121314151617181920212223242526272829303132
  1. package host
  2. import (
  3. "encoding/json"
  4. "log"
  5. "os"
  6. "github.com/gravitl/netmaker/cli/functions"
  7. "github.com/spf13/cobra"
  8. )
  9. var hostUpdateCmd = &cobra.Command{
  10. Use: "update HostID /path/to/host_definition.json",
  11. Args: cobra.ExactArgs(2),
  12. Short: "Update a host",
  13. Long: `Update a host`,
  14. Run: func(cmd *cobra.Command, args []string) {
  15. apiHost := &models.ApiHost{}
  16. content, err := os.ReadFile(args[1])
  17. if err != nil {
  18. log.Fatal("Error when opening file: ", err)
  19. }
  20. if err := json.Unmarshal(content, apiHost); err != nil {
  21. log.Fatal(err)
  22. }
  23. functions.PrettyPrint(functions.UpdateHost(args[0], apiHost))
  24. },
  25. }
  26. func init() {
  27. rootCmd.AddCommand(hostUpdateCmd)
  28. }