ctl.go 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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() {
  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. app.Flags = []cli.Flag{
  34. cli.BoolFlag{Name: "debug", Usage: "output cURL commands which can be used to reproduce the request"},
  35. cli.BoolFlag{Name: "no-sync", Usage: "don't synchronize cluster information before sending request"},
  36. cli.StringFlag{Name: "output, o", Value: "simple", Usage: "output response in the given format (`simple`, `extended` or `json`)"},
  37. cli.StringFlag{Name: "discovery-srv, D", Usage: "domain name to query for SRV records describing cluster endpoints"},
  38. cli.BoolFlag{Name: "insecure-discovery", Usage: "accept insecure SRV records describing cluster endpoints"},
  39. cli.StringFlag{Name: "peers, C", Value: "", Usage: "DEPRECATED - \"--endpoints\" should be used instead"},
  40. cli.StringFlag{Name: "endpoint", Value: "", Usage: "DEPRECATED - \"--endpoints\" should be used instead"},
  41. 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\")"},
  42. cli.StringFlag{Name: "cert-file", Value: "", Usage: "identify HTTPS client using this SSL certificate file"},
  43. cli.StringFlag{Name: "key-file", Value: "", Usage: "identify HTTPS client using this SSL key file"},
  44. cli.StringFlag{Name: "ca-file", Value: "", Usage: "verify certificates of HTTPS-enabled servers using this CA bundle"},
  45. cli.StringFlag{Name: "username, u", Value: "", Usage: "provide username[:password] and prompt if password is not supplied."},
  46. cli.DurationFlag{Name: "timeout", Value: 2 * time.Second, Usage: "connection timeout per request"},
  47. cli.DurationFlag{Name: "total-timeout", Value: 5 * time.Second, Usage: "timeout for the command execution (except watch)"},
  48. }
  49. app.Commands = []cli.Command{
  50. command.NewBackupCommand(),
  51. command.NewClusterHealthCommand(),
  52. command.NewMakeCommand(),
  53. command.NewMakeDirCommand(),
  54. command.NewRemoveCommand(),
  55. command.NewRemoveDirCommand(),
  56. command.NewGetCommand(),
  57. command.NewLsCommand(),
  58. command.NewSetCommand(),
  59. command.NewSetDirCommand(),
  60. command.NewUpdateCommand(),
  61. command.NewUpdateDirCommand(),
  62. command.NewWatchCommand(),
  63. command.NewExecWatchCommand(),
  64. command.NewMemberCommand(),
  65. command.NewUserCommands(),
  66. command.NewRoleCommands(),
  67. command.NewAuthCommands(),
  68. }
  69. err := app.Run(os.Args)
  70. if err != nil {
  71. fmt.Fprintln(os.Stderr, err)
  72. os.Exit(1)
  73. }
  74. }