ctl.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 ctlv3 contains the main entry point for the etcdctl for v3 API.
  15. package ctlv3
  16. import (
  17. "time"
  18. "github.com/coreos/etcd/etcdctl/ctlv3/command"
  19. "github.com/spf13/cobra"
  20. )
  21. const (
  22. cliName = "etcdctl"
  23. cliDescription = "A simple command line client for etcd3."
  24. defaultDialTimeout = 2 * time.Second
  25. defaultCommandTimeOut = 5 * time.Second
  26. )
  27. var (
  28. globalFlags = command.GlobalFlags{}
  29. )
  30. var (
  31. rootCmd = &cobra.Command{
  32. Use: cliName,
  33. Short: cliDescription,
  34. SuggestFor: []string{"etcdctl"},
  35. }
  36. )
  37. func init() {
  38. rootCmd.PersistentFlags().StringSliceVar(&globalFlags.Endpoints, "endpoints", []string{"127.0.0.1:2379"}, "gRPC endpoints")
  39. rootCmd.PersistentFlags().BoolVar(&globalFlags.Debug, "debug", false, "enable client-side debug logging")
  40. rootCmd.PersistentFlags().StringVarP(&globalFlags.OutputFormat, "write-out", "w", "simple", "set the output format (fields, json, protobuf, simple, table)")
  41. rootCmd.PersistentFlags().BoolVar(&globalFlags.IsHex, "hex", false, "print byte strings as hex encoded strings")
  42. rootCmd.PersistentFlags().DurationVar(&globalFlags.DialTimeout, "dial-timeout", defaultDialTimeout, "dial timeout for client connections")
  43. rootCmd.PersistentFlags().DurationVar(&globalFlags.CommandTimeOut, "command-timeout", defaultCommandTimeOut, "timeout for short running command (excluding dial timeout)")
  44. // TODO: secure by default when etcd enables secure gRPC by default.
  45. rootCmd.PersistentFlags().BoolVar(&globalFlags.Insecure, "insecure-transport", true, "disable transport security for client connections")
  46. rootCmd.PersistentFlags().BoolVar(&globalFlags.InsecureSkipVerify, "insecure-skip-tls-verify", false, "skip server certificate verification")
  47. rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.CertFile, "cert", "", "identify secure client using this TLS certificate file")
  48. rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.KeyFile, "key", "", "identify secure client using this TLS key file")
  49. rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.CAFile, "cacert", "", "verify certificates of TLS-enabled secure servers using this CA bundle")
  50. rootCmd.PersistentFlags().StringVar(&globalFlags.User, "user", "", "username[:password] for authentication (prompt if password is not supplied)")
  51. rootCmd.AddCommand(
  52. command.NewGetCommand(),
  53. command.NewPutCommand(),
  54. command.NewDelCommand(),
  55. command.NewTxnCommand(),
  56. command.NewCompactionCommand(),
  57. command.NewAlarmCommand(),
  58. command.NewDefragCommand(),
  59. command.NewEndpointCommand(),
  60. command.NewWatchCommand(),
  61. command.NewVersionCommand(),
  62. command.NewLeaseCommand(),
  63. command.NewMemberCommand(),
  64. command.NewSnapshotCommand(),
  65. command.NewMakeMirrorCommand(),
  66. command.NewMigrateCommand(),
  67. command.NewLockCommand(),
  68. command.NewElectCommand(),
  69. command.NewAuthCommand(),
  70. command.NewUserCommand(),
  71. command.NewRoleCommand(),
  72. command.NewCheckCommand(),
  73. )
  74. }
  75. func init() {
  76. cobra.EnablePrefixMatching = true
  77. }