go.etcd.io/etcd@v3.3.27+incompatible/etcdctl/ctlv2/ctl.go (about) 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 15 // Package ctlv2 contains the main entry point for the etcdctl for v2 API. 16 package ctlv2 17 18 import ( 19 "fmt" 20 "os" 21 "time" 22 23 "github.com/coreos/etcd/etcdctl/ctlv2/command" 24 "github.com/coreos/etcd/version" 25 "github.com/urfave/cli" 26 ) 27 28 func Start(apiv string) { 29 app := cli.NewApp() 30 app.Name = "etcdctl" 31 app.Version = version.Version 32 cli.VersionPrinter = func(c *cli.Context) { 33 fmt.Fprintf(c.App.Writer, "etcdctl version: %v\n", c.App.Version) 34 fmt.Fprintln(c.App.Writer, "API version: 2") 35 } 36 app.Usage = "A simple command line client for etcd." 37 38 if apiv == "" { 39 app.Usage += "\n\n" + 40 "WARNING:\n" + 41 " Environment variable ETCDCTL_API is not set; defaults to etcdctl v2.\n" + 42 " Set environment variable ETCDCTL_API=3 to use v3 API or ETCDCTL_API=2 to use v2 API." 43 } 44 45 app.Flags = []cli.Flag{ 46 cli.BoolFlag{Name: "debug", Usage: "output cURL commands which can be used to reproduce the request"}, 47 cli.BoolFlag{Name: "no-sync", Usage: "don't synchronize cluster information before sending request"}, 48 cli.StringFlag{Name: "output, o", Value: "simple", Usage: "output response in the given format (`simple`, `extended` or `json`)"}, 49 cli.StringFlag{Name: "discovery-srv, D", Usage: "domain name to query for SRV records describing cluster endpoints"}, 50 cli.BoolFlag{Name: "insecure-discovery", Usage: "accept insecure SRV records describing cluster endpoints"}, 51 cli.StringFlag{Name: "peers, C", Value: "", Usage: "DEPRECATED - \"--endpoints\" should be used instead"}, 52 cli.StringFlag{Name: "endpoint", Value: "", Usage: "DEPRECATED - \"--endpoints\" should be used instead"}, 53 cli.StringFlag{Name: "endpoints", Value: "", Usage: "a comma-delimited list of machine addresses in the cluster (default: \"http://127.0.0.1:2379,http://127.0.0.1:4001\")"}, 54 cli.StringFlag{Name: "cert-file", Value: "", Usage: "identify HTTPS client using this SSL certificate file"}, 55 cli.StringFlag{Name: "key-file", Value: "", Usage: "identify HTTPS client using this SSL key file"}, 56 cli.StringFlag{Name: "ca-file", Value: "", Usage: "verify certificates of HTTPS-enabled servers using this CA bundle"}, 57 cli.StringFlag{Name: "username, u", Value: "", Usage: "provide username[:password] and prompt if password is not supplied."}, 58 cli.DurationFlag{Name: "timeout", Value: 2 * time.Second, Usage: "connection timeout per request"}, 59 cli.DurationFlag{Name: "total-timeout", Value: 5 * time.Second, Usage: "timeout for the command execution (except watch)"}, 60 } 61 app.Commands = []cli.Command{ 62 command.NewBackupCommand(), 63 command.NewClusterHealthCommand(), 64 command.NewMakeCommand(), 65 command.NewMakeDirCommand(), 66 command.NewRemoveCommand(), 67 command.NewRemoveDirCommand(), 68 command.NewGetCommand(), 69 command.NewLsCommand(), 70 command.NewSetCommand(), 71 command.NewSetDirCommand(), 72 command.NewUpdateCommand(), 73 command.NewUpdateDirCommand(), 74 command.NewWatchCommand(), 75 command.NewExecWatchCommand(), 76 command.NewMemberCommand(), 77 command.NewUserCommands(), 78 command.NewRoleCommands(), 79 command.NewAuthCommands(), 80 } 81 82 err := runCtlV2(app) 83 if err != nil { 84 fmt.Fprintln(os.Stderr, err) 85 os.Exit(1) 86 } 87 }