ctl.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2015 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. // Package ctlv2 contains the main entry point for the etcdctl for v2 API.
  15. package ctlv2
  16. import (
  17. "fmt"
  18. "os"
  19. "time"
  20. "github.com/coreos/etcd/etcdctl/ctlv2/command"
  21. "github.com/coreos/etcd/version"
  22. "github.com/urfave/cli"
  23. )
  24. func Start(apiv string) {
  25. app := cli.NewApp()
  26. app.Name = "etcdctl"
  27. app.Version = version.Version
  28. cli.VersionPrinter = func(c *cli.Context) {
  29. fmt.Fprintf(c.App.Writer, "etcdctl version: %v\n", c.App.Version)
  30. fmt.Fprintln(c.App.Writer, "API version: 2")
  31. }
  32. app.Usage = "A simple command line client for etcd."
  33. if apiv == "" {
  34. app.Usage += "\n\n" +
  35. "WARNING:\n" +
  36. " Environment variable ETCDCTL_API is not set; defaults to etcdctl v2.\n" +
  37. " Set environment variable ETCDCTL_API=3 to use v3 API or ETCDCTL_API=2 to use v2 API."
  38. }
  39. app.Flags = []cli.Flag{
  40. cli.BoolFlag{Name: "debug", Usage: "output cURL commands which can be used to reproduce the request"},
  41. cli.BoolFlag{Name: "no-sync", Usage: "don't synchronize cluster information before sending request"},
  42. cli.StringFlag{Name: "output, o", Value: "simple", Usage: "output response in the given format (`simple`, `extended` or `json`)"},
  43. cli.StringFlag{Name: "discovery-srv, D", Usage: "domain name to query for SRV records describing cluster endpoints"},
  44. cli.BoolFlag{Name: "insecure-discovery", Usage: "accept insecure SRV records describing cluster endpoints"},
  45. cli.StringFlag{Name: "peers, C", Value: "", Usage: "DEPRECATED - \"--endpoints\" should be used instead"},
  46. cli.StringFlag{Name: "endpoint", Value: "", Usage: "DEPRECATED - \"--endpoints\" should be used instead"},
  47. cli.StringFlag{Name: "endpoints", Value: "", Usage: "a comma-delimited list of machine addresses in the cluster (default: \"http://127.0.0.1:2379,http://127.0.0.1:4001\")"},
  48. cli.StringFlag{Name: "cert-file", Value: "", Usage: "identify HTTPS client using this SSL certificate file"},
  49. cli.StringFlag{Name: "key-file", Value: "", Usage: "identify HTTPS client using this SSL key file"},
  50. cli.StringFlag{Name: "ca-file", Value: "", Usage: "verify certificates of HTTPS-enabled servers using this CA bundle"},
  51. cli.StringFlag{Name: "username, u", Value: "", Usage: "provide username[:password] and prompt if password is not supplied."},
  52. cli.DurationFlag{Name: "timeout", Value: 2 * time.Second, Usage: "connection timeout per request"},
  53. cli.DurationFlag{Name: "total-timeout", Value: 5 * time.Second, Usage: "timeout for the command execution (except watch)"},
  54. }
  55. app.Commands = []cli.Command{
  56. command.NewBackupCommand(),
  57. command.NewClusterHealthCommand(),
  58. command.NewMakeCommand(),
  59. command.NewMakeDirCommand(),
  60. command.NewRemoveCommand(),
  61. command.NewRemoveDirCommand(),
  62. command.NewGetCommand(),
  63. command.NewLsCommand(),
  64. command.NewSetCommand(),
  65. command.NewSetDirCommand(),
  66. command.NewUpdateCommand(),
  67. command.NewUpdateDirCommand(),
  68. command.NewWatchCommand(),
  69. command.NewExecWatchCommand(),
  70. command.NewMemberCommand(),
  71. command.NewUserCommands(),
  72. command.NewRoleCommands(),
  73. command.NewAuthCommands(),
  74. }
  75. err := runCtlV2(app)
  76. if err != nil {
  77. fmt.Fprintln(os.Stderr, err)
  78. os.Exit(1)
  79. }
  80. }