mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-29 06:31:10 +01:00
command/write: handle writes with output
This commit is contained in:
parent
5aee91ccb9
commit
f2fe8dac79
@ -18,7 +18,9 @@ type WriteCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *WriteCommand) Run(args []string) int {
|
func (c *WriteCommand) Run(args []string) int {
|
||||||
|
var format string
|
||||||
flags := c.Meta.FlagSet("write", FlagSetDefault)
|
flags := c.Meta.FlagSet("write", FlagSetDefault)
|
||||||
|
flags.StringVar(&format, "format", "table", "")
|
||||||
flags.Usage = func() { c.Ui.Error(c.Help()) }
|
flags.Usage = func() { c.Ui.Error(c.Help()) }
|
||||||
if err := flags.Parse(args); err != nil {
|
if err := flags.Parse(args); err != nil {
|
||||||
return 1
|
return 1
|
||||||
@ -50,16 +52,21 @@ func (c *WriteCommand) Run(args []string) int {
|
|||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := client.Logical().Write(path, data); err != nil {
|
secret, err := client.Logical().Write(path, data)
|
||||||
|
if err != nil {
|
||||||
c.Ui.Error(fmt.Sprintf(
|
c.Ui.Error(fmt.Sprintf(
|
||||||
"Error writing data to %s: %s", path, err))
|
"Error writing data to %s: %s", path, err))
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if secret == nil {
|
||||||
c.Ui.Output(fmt.Sprintf("Success! Data written to: %s", path))
|
c.Ui.Output(fmt.Sprintf("Success! Data written to: %s", path))
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return OutputSecret(c.Ui, format, secret)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *WriteCommand) parseData(args []string) (map[string]interface{}, error) {
|
func (c *WriteCommand) parseData(args []string) (map[string]interface{}, error) {
|
||||||
var stdin io.Reader = os.Stdin
|
var stdin io.Reader = os.Stdin
|
||||||
if c.testStdin != nil {
|
if c.testStdin != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user