leave.go 976 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2024-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. package cli
  14. import (
  15. "fmt"
  16. "os"
  17. "strconv"
  18. "zerotier/pkg/zerotier"
  19. )
  20. // Leave CLI command
  21. func Leave(basePath, authToken string, args []string) {
  22. if len(args) != 1 {
  23. Help()
  24. os.Exit(1)
  25. }
  26. if len(args[0]) != zerotier.NetworkIDStringLength {
  27. fmt.Printf("ERROR: invalid network ID: %s\n", args[0])
  28. os.Exit(1)
  29. }
  30. nwid, err := strconv.ParseUint(args[0], 16, 64)
  31. if err != nil {
  32. fmt.Printf("ERROR: invalid network ID: %s\n", args[0])
  33. os.Exit(1)
  34. }
  35. nwids := fmt.Sprintf("%.16x", nwid)
  36. apiDelete(basePath, authToken, "/network/"+nwids, nil)
  37. fmt.Printf("OK %s", nwids)
  38. os.Exit(0)
  39. }