update.go 742 B

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