ctl.go 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. 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.CAFile, "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().StringVarP(&globalFlags.TLS.ServerName, "discovery-srv", "d", "", "domain name to query for SRV records describing cluster endpoints")
  57. rootCmd.AddCommand(
  58. command.NewGetCommand(),
  59. command.NewPutCommand(),
  60. command.NewDelCommand(),
  61. command.NewTxnCommand(),
  62. command.NewCompactionCommand(),
  63. command.NewAlarmCommand(),
  64. command.NewDefragCommand(),
  65. command.NewEndpointCommand(),
  66. command.NewMoveLeaderCommand(),
  67. command.NewWatchCommand(),
  68. command.NewVersionCommand(),
  69. command.NewLeaseCommand(),
  70. command.NewMemberCommand(),
  71. command.NewSnapshotCommand(),
  72. command.NewMakeMirrorCommand(),
  73. command.NewMigrateCommand(),
  74. command.NewLockCommand(),
  75. command.NewElectCommand(),
  76. command.NewAuthCommand(),
  77. command.NewUserCommand(),
  78. command.NewRoleCommand(),
  79. command.NewCheckCommand(),
  80. )
  81. }
  82. func init() {
  83. cobra.EnablePrefixMatching = true
  84. }