Add the ability to print curl commands from CLI (#6113)

This commit is contained in:
Jeff Mitchell
2019-02-01 17:13:51 -05:00
committed by GitHub
parent d647681a37
commit f404e0acd2
7 changed files with 218 additions and 7 deletions

View File

@@ -50,8 +50,9 @@ type BaseCommand struct {
flagTLSSkipVerify bool
flagWrapTTL time.Duration
flagFormat string
flagField string
flagFormat string
flagField string
flagOutputCurlString bool
flagMFA []string
@@ -78,6 +79,10 @@ func (c *BaseCommand) Client() (*api.Client, error) {
config.Address = c.flagAddress
}
if c.flagOutputCurlString {
config.OutputCurlString = c.flagOutputCurlString
}
// If we need custom TLS configuration, then set it
if c.flagCACert != "" || c.flagCAPath != "" || c.flagClientCert != "" ||
c.flagClientKey != "" || c.flagTLSServerName != "" || c.flagTLSSkipVerify {
@@ -325,6 +330,15 @@ func (c *BaseCommand) flagSet(bit FlagSetBit) *FlagSets {
Completion: complete.PredictAnything,
Usage: "Supply MFA credentials as part of X-Vault-MFA header.",
})
f.BoolVar(&BoolVar{
Name: "output-curl-string",
Target: &c.flagOutputCurlString,
Default: false,
Usage: "Instead of executing the request, print an equivalent cURL " +
"command string and exit.",
})
}
if bit&(FlagSetOutputField|FlagSetOutputFormat) != 0 {