main.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2016 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // etcdctl is a command line application that controls etcd.
  15. package main
  16. import (
  17. "fmt"
  18. "os"
  19. "go.etcd.io/etcd/etcdctl/ctlv2"
  20. "go.etcd.io/etcd/etcdctl/ctlv3"
  21. )
  22. const (
  23. apiEnv = "ETCDCTL_API"
  24. )
  25. func main() {
  26. apiv := os.Getenv(apiEnv)
  27. // unset apiEnv to avoid side-effect for future env and flag parsing.
  28. os.Unsetenv(apiEnv)
  29. if len(apiv) == 0 || apiv == "3" {
  30. ctlv3.Start()
  31. return
  32. }
  33. if apiv == "2" {
  34. ctlv2.Start()
  35. return
  36. }
  37. fmt.Fprintln(os.Stderr, "unsupported API version", apiv)
  38. os.Exit(1)
  39. }