|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/carapace-sh/carapace" |
| 5 | + "github.com/carapace-sh/carapace-bin/pkg/actions/net/http" |
| 6 | + "github.com/spf13/cobra" |
| 7 | +) |
| 8 | + |
| 9 | +var rootCmd = &cobra.Command{ |
| 10 | + Use: "xh", |
| 11 | + Short: "Friendly and fast tool for sending HTTP requests", |
| 12 | + Long: "https://github.com/ducaale/xh", |
| 13 | + Run: func(cmd *cobra.Command, args []string) {}, |
| 14 | +} |
| 15 | + |
| 16 | +func Execute() error { |
| 17 | + return rootCmd.Execute() |
| 18 | +} |
| 19 | +func init() { |
| 20 | + carapace.Gen(rootCmd).Standalone() |
| 21 | + |
| 22 | + rootCmd.Flags().Bool("all", false, "Show any intermediary requests/responses while following redirects with --follow") |
| 23 | + rootCmd.Flags().StringP("auth", "a", "", "Authenticate as USER with PASS (-A basic|digest) or with TOKEN (-A bearer)") |
| 24 | + rootCmd.Flags().StringP("auth-type", "A", "", "Specify the auth mechanism") |
| 25 | + rootCmd.Flags().BoolP("body", "b", false, "Print only the response body. Shortcut for --print=b") |
| 26 | + rootCmd.Flags().String("cert", "", "Use a client side certificate for SSL") |
| 27 | + rootCmd.Flags().String("cert-key", "", "A private key file to use with --cert") |
| 28 | + rootCmd.Flags().Bool("check-status", true, "Exit with an error status code if the server replies with an error") |
| 29 | + rootCmd.Flags().BoolP("compress", "x", false, "Content compressed (encoded) with Deflate algorithm") |
| 30 | + // TODO: according to the description, --continue can only be used if --download and --output are used |
| 31 | + // how can we tell carapace to conditonally show flags based on existance of others? |
| 32 | + rootCmd.Flags().BoolP("continue", "c", false, "Resume an interrupted download. Requires --download and --output") |
| 33 | + rootCmd.Flags().Bool("curl", false, "Print a translation to a curl command") |
| 34 | + rootCmd.Flags().Bool("curl-long", false, "Use the long versions of curl's flags") |
| 35 | + rootCmd.Flags().Bool("debug", false, "Print full error stack traces and debug log messages") |
| 36 | + rootCmd.Flags().BoolP("download", "d", false, "Download the body to a file instead of printing it") |
| 37 | + rootCmd.Flags().BoolP("follow", "F", false, "Do follow redirects") |
| 38 | + rootCmd.Flags().BoolP("form", "f", false, "Serialize data items from the command line as form fields") |
| 39 | + rootCmd.Flags().String("format-options", "", "Set output formatting options") |
| 40 | + rootCmd.Flags().String("generate", "", "Generate shell completions or man pages") |
| 41 | + rootCmd.Flags().BoolP("headers", "h", false, "Print only the response headers. Shortcut for --print=h") |
| 42 | + rootCmd.Flags().Bool("help", false, "Print help") |
| 43 | + rootCmd.Flags().StringP("history-print", "P", "", "The same as --print but applies only to intermediary requests/responses") |
| 44 | + rootCmd.Flags().String("http-version", "", "HTTP version to use") |
| 45 | + rootCmd.Flags().Bool("https", false, "Make HTTPS requests if not specified in the URL") |
| 46 | + rootCmd.Flags().Bool("ignore-netrc", false, "Do not use credentials from .netrc") |
| 47 | + rootCmd.Flags().BoolP("ignore-stdin", "I", false, "Do not attempt to read stdin") |
| 48 | + rootCmd.Flags().String("interface", "", "Bind to a network interface or local IP address") |
| 49 | + rootCmd.Flags().StringP("ipv4", "4", "", "Resolve hostname to ipv4 addresses only") |
| 50 | + rootCmd.Flags().StringP("ipv6", "6", "", "Resolve hostname to ipv6 addresses only") |
| 51 | + rootCmd.Flags().BoolP("json", "j", true, "Serialize data items from the command line as a JSON object") |
| 52 | + // TODO: according to the description, --max-redirects can only be used if --follow is used |
| 53 | + // how can we tell carapace to conditonally show flags based on existance of others? |
| 54 | + rootCmd.Flags().Int("max-redirects", 0, "Number of redirects to follow. Only respected if --follow is used") |
| 55 | + rootCmd.Flags().BoolP("meta", "m", false, "Print only the response metadata. Shortcut for --print=m") |
| 56 | + rootCmd.Flags().Bool("multipart", false, "Like --form, but force a multipart/form-data request even without files") |
| 57 | + rootCmd.Flags().Bool("offline", false, "Construct HTTP requests without sending them anywhere") |
| 58 | + rootCmd.Flags().StringP("output", "o", "", "Save output to FILE instead of stdout") |
| 59 | + rootCmd.Flags().String("pretty", "", "Controls output processing") |
| 60 | + rootCmd.Flags().StringP("print", "p", "", "String specifying what the output should contain") |
| 61 | + rootCmd.Flags().String("proxy", "", "Use a proxy for a protocol. For example: --proxy https:http://proxy.host:8080") |
| 62 | + rootCmd.Flags().BoolP("quiet", "q", false, "Do not print to stdout or stderr") |
| 63 | + rootCmd.Flags().String("raw", "", "Pass raw request data without extra processing") |
| 64 | + rootCmd.Flags().String("resolve", "", "Override DNS resolution for specific domain to a custom IP") |
| 65 | + rootCmd.Flags().String("response-charset", "", "Override the response encoding for terminal display purposes") |
| 66 | + rootCmd.Flags().String("response-mime", "", "Override the response mime type for coloring and formatting for the terminal") |
| 67 | + rootCmd.Flags().String("session", "", "Create, or reuse and update a session") |
| 68 | + rootCmd.Flags().String("session-read-only", "", "Create or read a session without updating it form the request/response exchange") |
| 69 | + rootCmd.Flags().String("ssl", "", "Force a particular TLS version") |
| 70 | + rootCmd.Flags().BoolP("stream", "S", false, "Always stream the response body") |
| 71 | + rootCmd.Flags().StringP("style", "s", "", "Output coloring style") |
| 72 | + rootCmd.Flags().Int("timeout", 0, "Connection timeout of the request") |
| 73 | + rootCmd.Flags().BoolP("verbose", "v", false, "Print the whole request as well as the response") |
| 74 | + rootCmd.Flags().String("verify", "", "If 'no', skip SSL verification. If a file path, use it as a CA bundle") |
| 75 | + rootCmd.Flags().BoolP("version", "V", false, "Print version") |
| 76 | + |
| 77 | + rootCmd.MarkFlagsMutuallyExclusive("json", "form", "multipart") |
| 78 | + |
| 79 | + carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{ |
| 80 | + "auth-type": carapace.ActionValues("basic", "bearer", "digest"), |
| 81 | + "cert": carapace.ActionFiles(), |
| 82 | + "cert-key": carapace.ActionFiles(), |
| 83 | + "history-print": carapace.ActionValues("h", "b", "m").UniqueList(""), |
| 84 | + "http-version": carapace.ActionValues("1.0", "1.1", "2", "2-prior-knowledge"), |
| 85 | + "output": carapace.ActionFiles(), |
| 86 | + "pretty": carapace.ActionValues("all", "colors", "format", "none"), |
| 87 | + "print": carapace.ActionValues("h", "b", "m").UniqueList(""), |
| 88 | + "session": carapace.ActionFiles(), |
| 89 | + "session-read-only": carapace.ActionFiles(), |
| 90 | + "ssl": carapace.ActionValues("auto", "tls1", "tls1.1", "tls1.2", "tls1.3"), |
| 91 | + "style": carapace.ActionValues("auto", "solarized", "monokai", "fruity"), |
| 92 | + "verify": carapace.Batch( |
| 93 | + carapace.ActionValuesDescribed("no", "Skip SSL verification"), |
| 94 | + carapace.ActionFiles(), |
| 95 | + ).ToA(), |
| 96 | + }) |
| 97 | + |
| 98 | + carapace.Gen(rootCmd).PositionalCompletion( |
| 99 | + http.ActionRequestMethods(), |
| 100 | + ) |
| 101 | +} |
0 commit comments