main.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2015 CoreOS, Inc.
  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. // etcdctlv3 is a command line application that utilizes v3 API.
  15. package main
  16. import (
  17. "text/tabwriter"
  18. "github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra"
  19. "github.com/coreos/etcd/etcdctlv3/command"
  20. )
  21. const (
  22. cliName = "etcdctlv3"
  23. cliDescription = "A simple command line client for etcd3."
  24. )
  25. var (
  26. tabOut *tabwriter.Writer
  27. globalFlags = command.GlobalFlags{}
  28. )
  29. var (
  30. rootCmd = &cobra.Command{
  31. Use: cliName,
  32. Short: cliDescription,
  33. SuggestFor: []string{"etcctlv3", "etcdcltv3", "etlctlv3"},
  34. }
  35. )
  36. func init() {
  37. rootCmd.PersistentFlags().StringSliceVar(&globalFlags.Endpoints, "endpoints", []string{"127.0.0.1:2378", "127.0.0.1:22378", "127.0.0.1:32378"}, "gRPC endpoints")
  38. rootCmd.PersistentFlags().StringVarP(&globalFlags.OutputFormat, "write-out", "w", "simple", "set the output format (simple, json, protobuf)")
  39. rootCmd.PersistentFlags().BoolVar(&globalFlags.IsHex, "hex", false, "print byte strings as hex encoded strings")
  40. rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.CertFile, "cert", "", "identify secure client using this TLS certificate file")
  41. rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.KeyFile, "key", "", "identify secure client using this TLS key file")
  42. rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.CAFile, "cacert", "", "verify certificates of TLS-enabled secure servers using this CA bundle")
  43. rootCmd.AddCommand(
  44. command.NewGetCommand(),
  45. command.NewPutCommand(),
  46. command.NewDelCommand(),
  47. command.NewTxnCommand(),
  48. command.NewCompactionCommand(),
  49. command.NewDefragCommand(),
  50. command.NewWatchCommand(),
  51. command.NewVersionCommand(),
  52. command.NewLeaseCommand(),
  53. command.NewMemberCommand(),
  54. command.NewSnapshotCommand(),
  55. command.NewMakeMirrorCommand(),
  56. command.NewLockCommand(),
  57. command.NewAuthCommand(),
  58. command.NewElectCommand(),
  59. )
  60. }
  61. func init() {
  62. cobra.EnablePrefixMatching = true
  63. }
  64. func main() {
  65. rootCmd.SetUsageFunc(usageFunc)
  66. // Make help just show the usage
  67. rootCmd.SetHelpTemplate(`{{.UsageString}}`)
  68. if err := rootCmd.Execute(); err != nil {
  69. command.ExitWithError(command.ExitError, err)
  70. }
  71. }