ctl.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. "go.etcd.io/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. defaultKeepAliveTime = 2 * time.Second
  27. defaultKeepAliveTimeOut = 6 * time.Second
  28. )
  29. var (
  30. globalFlags = command.GlobalFlags{}
  31. )
  32. var (
  33. rootCmd = &cobra.Command{
  34. Use: cliName,
  35. Short: cliDescription,
  36. SuggestFor: []string{"etcdctl"},
  37. }
  38. )
  39. func init() {
  40. rootCmd.PersistentFlags().StringSliceVar(&globalFlags.Endpoints, "endpoints", []string{"127.0.0.1:2379"}, "gRPC endpoints")
  41. rootCmd.PersistentFlags().BoolVar(&globalFlags.Debug, "debug", false, "enable client-side debug logging")
  42. rootCmd.PersistentFlags().StringVarP(&globalFlags.OutputFormat, "write-out", "w", "simple", "set the output format (fields, json, protobuf, simple, table)")
  43. rootCmd.PersistentFlags().BoolVar(&globalFlags.IsHex, "hex", false, "print byte strings as hex encoded strings")
  44. rootCmd.PersistentFlags().DurationVar(&globalFlags.DialTimeout, "dial-timeout", defaultDialTimeout, "dial timeout for client connections")
  45. rootCmd.PersistentFlags().DurationVar(&globalFlags.CommandTimeOut, "command-timeout", defaultCommandTimeOut, "timeout for short running command (excluding dial timeout)")
  46. rootCmd.PersistentFlags().DurationVar(&globalFlags.KeepAliveTime, "keepalive-time", defaultKeepAliveTime, "keepalive time for client connections")
  47. rootCmd.PersistentFlags().DurationVar(&globalFlags.KeepAliveTimeout, "keepalive-timeout", defaultKeepAliveTimeOut, "keepalive timeout for client connections")
  48. // TODO: secure by default when etcd enables secure gRPC by default.
  49. rootCmd.PersistentFlags().BoolVar(&globalFlags.Insecure, "insecure-transport", true, "disable transport security for client connections")
  50. rootCmd.PersistentFlags().BoolVar(&globalFlags.InsecureDiscovery, "insecure-discovery", true, "accept insecure SRV records describing cluster endpoints")
  51. rootCmd.PersistentFlags().BoolVar(&globalFlags.InsecureSkipVerify, "insecure-skip-tls-verify", false, "skip server certificate verification")
  52. rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.CertFile, "cert", "", "identify secure client using this TLS certificate file")
  53. rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.KeyFile, "key", "", "identify secure client using this TLS key file")
  54. rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.TrustedCAFile, "cacert", "", "verify certificates of TLS-enabled secure servers using this CA bundle")
  55. rootCmd.PersistentFlags().StringVar(&globalFlags.User, "user", "", "username[:password] for authentication (prompt if password is not supplied)")
  56. rootCmd.PersistentFlags().StringVar(&globalFlags.Password, "password", "", "password for authentication (if this option is used, --user option shouldn't include password)")
  57. rootCmd.PersistentFlags().StringVarP(&globalFlags.TLS.ServerName, "discovery-srv", "d", "", "domain name to query for SRV records describing cluster endpoints")
  58. rootCmd.PersistentFlags().StringVarP(&globalFlags.DNSClusterServiceName, "discovery-srv-name", "", "", "service name to query when using DNS discovery")
  59. rootCmd.AddCommand(
  60. command.NewGetCommand(),
  61. command.NewPutCommand(),
  62. command.NewDelCommand(),
  63. command.NewTxnCommand(),
  64. command.NewCompactionCommand(),
  65. command.NewAlarmCommand(),
  66. command.NewDefragCommand(),
  67. command.NewEndpointCommand(),
  68. command.NewMoveLeaderCommand(),
  69. command.NewWatchCommand(),
  70. command.NewVersionCommand(),
  71. command.NewLeaseCommand(),
  72. command.NewMemberCommand(),
  73. command.NewSnapshotCommand(),
  74. command.NewMakeMirrorCommand(),
  75. command.NewMigrateCommand(),
  76. command.NewLockCommand(),
  77. command.NewElectCommand(),
  78. command.NewAuthCommand(),
  79. command.NewUserCommand(),
  80. command.NewRoleCommand(),
  81. command.NewCheckCommand(),
  82. )
  83. }
  84. func init() {
  85. cobra.EnablePrefixMatching = true
  86. }