(args []string)
| 110 | } |
| 111 | |
| 112 | func (c *WriteCommand) Run(args []string) int { |
| 113 | f := c.Flags() |
| 114 | |
| 115 | if err := f.Parse(args); err != nil { |
| 116 | c.UI.Error(err.Error()) |
| 117 | return 1 |
| 118 | } |
| 119 | |
| 120 | args = f.Args() |
| 121 | switch { |
| 122 | case len(args) < 1: |
| 123 | c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args))) |
| 124 | return 1 |
| 125 | case len(args) == 1 && !c.flagForce: |
| 126 | c.UI.Error("Must supply data or use -force") |
| 127 | return 1 |
| 128 | } |
| 129 | |
| 130 | // Pull our fake stdin if needed |
| 131 | stdin := (io.Reader)(os.Stdin) |
| 132 | if c.testStdin != nil { |
| 133 | stdin = c.testStdin |
| 134 | } |
| 135 | |
| 136 | path := sanitizePath(args[0]) |
| 137 | |
| 138 | data, err := parseArgsData(stdin, args[1:]) |
| 139 | if err != nil { |
| 140 | c.UI.Error(fmt.Sprintf("Failed to parse K=V data: %s", err)) |
| 141 | return 1 |
| 142 | } |
| 143 | |
| 144 | client, err := c.Client() |
| 145 | if err != nil { |
| 146 | c.UI.Error(err.Error()) |
| 147 | return 2 |
| 148 | } |
| 149 | |
| 150 | secret, err := client.Logical().Write(path, data) |
| 151 | return handleWriteSecretOutput(c.BaseCommand, path, secret, err) |
| 152 | } |
| 153 | |
| 154 | func handleWriteSecretOutput(c *BaseCommand, path string, secret *api.Secret, err error) int { |
| 155 | if err != nil { |
nothing calls this directly
no test coverage detected