main.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2016 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. // etcd-runner is a command line application that performs tests on etcd.
  15. package main
  16. import (
  17. "log"
  18. "time"
  19. "github.com/coreos/etcd/tools/functional-tester/etcd-runner/command"
  20. "github.com/spf13/cobra"
  21. )
  22. const (
  23. cliName = "etcdctl"
  24. cliDescription = "A simple command line client for etcd3."
  25. defaultDialTimeout = 2 * 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. log.SetFlags(log.Lmicroseconds)
  39. rootCmd.PersistentFlags().StringSliceVar(&globalFlags.Endpoints, "endpoints", []string{"127.0.0.1:2379"}, "gRPC endpoints")
  40. rootCmd.PersistentFlags().DurationVar(&globalFlags.DialTimeout, "dial-timeout", defaultDialTimeout, "dial timeout for client connections")
  41. rootCmd.AddCommand(
  42. command.NewElectionCommand(),
  43. command.NewLeaseRenewerCommand(),
  44. command.NewLockRacerCommand(),
  45. command.NewWatchCommand(),
  46. )
  47. }
  48. func init() {
  49. cobra.EnablePrefixMatching = true
  50. }
  51. func Start() {
  52. rootCmd.SetUsageFunc(usageFunc)
  53. // Make help just show the usage
  54. rootCmd.SetHelpTemplate(`{{.UsageString}}`)
  55. if err := rootCmd.Execute(); err != nil {
  56. command.ExitWithError(command.ExitError, err)
  57. }
  58. }
  59. func main() {
  60. Start()
  61. }