|
87 | 87 |
|
88 | 88 | // Print the pgbackrest info output received. |
89 | 89 | cmd.Printf("BACKUP\n\n") |
90 | | - if err := newShowBackupCommand(config).RunE(cmd, args); err != nil { |
| 90 | + if stdout, stderr, err := showBackup(config, args, "text", ""); err != nil { |
91 | 91 | return err |
| 92 | + } else { |
| 93 | + cmd.Printf(stdout) |
| 94 | + if stderr != "" { |
| 95 | + cmd.Printf("\nError returned: %s\n", stderr) |
| 96 | + } |
92 | 97 | } |
93 | 98 |
|
94 | 99 | // Print the patronictl list output received. |
95 | 100 | cmd.Printf("\nHA\n\n") |
96 | | - return newShowHACommand(config).RunE(cmd, args) |
| 101 | + if stdout, stderr, err := showHA(config, args, "pretty"); err != nil { |
| 102 | + return err |
| 103 | + } else { |
| 104 | + cmd.Printf(stdout) |
| 105 | + if stderr != "" { |
| 106 | + cmd.Printf("\nError returned: %s\n", stderr) |
| 107 | + } |
| 108 | + } |
| 109 | + return nil |
97 | 110 | } |
98 | 111 |
|
99 | 112 | return cmdShow |
@@ -164,28 +177,37 @@ stanza: db |
164 | 177 | // handle validation. |
165 | 178 | repoNum := strings.TrimPrefix(repoName, "repo") |
166 | 179 |
|
167 | | - exec, err := getPrimaryExec(config, args) |
168 | | - if err != nil { |
169 | | - return err |
170 | | - } |
| 180 | + stdout, stderr, err := showBackup(config, args, outputEnum.String(), repoNum) |
171 | 181 |
|
172 | | - stdout, stderr, err := Executor(exec).pgBackRestInfo(outputEnum.String(), repoNum) |
173 | | - if err != nil { |
174 | | - return err |
| 182 | + if err == nil { |
| 183 | + cmd.Printf(stdout) |
| 184 | + if stderr != "" { |
| 185 | + cmd.Printf("\nError returned: %s\n", stderr) |
| 186 | + } |
175 | 187 | } |
176 | 188 |
|
177 | | - // Print the output received. |
178 | | - cmd.Printf(stdout) |
179 | | - if stderr != "" { |
180 | | - cmd.Printf("\nError returned: %s\n", stderr) |
181 | | - } |
182 | | - |
183 | | - return nil |
| 189 | + return err |
184 | 190 | } |
185 | 191 |
|
186 | 192 | return cmdShowBackup |
187 | 193 | } |
188 | 194 |
|
| 195 | +// showBackup execs into the primary Pod, runs the 'pgbackrest info' command and |
| 196 | +// returns the command output and/or error |
| 197 | +func showBackup( |
| 198 | + config *internal.Config, |
| 199 | + args []string, |
| 200 | + output string, |
| 201 | + repoNum string) (string, string, error) { |
| 202 | + |
| 203 | + exec, err := getPrimaryExec(config, args) |
| 204 | + if err != nil { |
| 205 | + return "", "", err |
| 206 | + } |
| 207 | + |
| 208 | + return Executor(exec).pgBackRestInfo(output, repoNum) |
| 209 | +} |
| 210 | + |
189 | 211 | // newShowHACommand returns the output of the 'patronictl list' command. |
190 | 212 | // - https://patroni.readthedocs.io/en/latest/patronictl.html#patronictl-list |
191 | 213 | func newShowHACommand(config *internal.Config) *cobra.Command { |
@@ -227,28 +249,35 @@ pgo show ha hippo --output json |
227 | 249 | // Define the 'show backup' command |
228 | 250 | cmdShowHA.RunE = func(cmd *cobra.Command, args []string) error { |
229 | 251 |
|
230 | | - exec, err := getPrimaryExec(config, args) |
231 | | - if err != nil { |
232 | | - return err |
233 | | - } |
234 | | - |
235 | | - stdout, stderr, err := Executor(exec).patronictl("list", outputEnum.String()) |
236 | | - if err != nil { |
237 | | - return err |
238 | | - } |
| 252 | + stdout, stderr, err := showHA(config, args, outputEnum.String()) |
239 | 253 |
|
240 | | - // Print the output received. |
241 | | - cmd.Printf(stdout) |
242 | | - if stderr != "" { |
243 | | - cmd.Printf("\nError returned: %s\n", stderr) |
| 254 | + if err == nil { |
| 255 | + cmd.Printf(stdout) |
| 256 | + if stderr != "" { |
| 257 | + cmd.Printf("\nError returned: %s\n", stderr) |
| 258 | + } |
244 | 259 | } |
245 | 260 |
|
246 | | - return nil |
| 261 | + return err |
247 | 262 | } |
248 | 263 |
|
249 | 264 | return cmdShowHA |
250 | 265 | } |
251 | 266 |
|
| 267 | +// showHA execs into the primary Pod, runs the 'patronictl list' command and |
| 268 | +// returns the command output and/or error |
| 269 | +func showHA( |
| 270 | + config *internal.Config, |
| 271 | + args []string, |
| 272 | + output string) (string, string, error) { |
| 273 | + exec, err := getPrimaryExec(config, args) |
| 274 | + if err != nil { |
| 275 | + return "", "", err |
| 276 | + } |
| 277 | + |
| 278 | + return Executor(exec).patronictl("list", output) |
| 279 | +} |
| 280 | + |
252 | 281 | // getPrimaryExec returns a executor function for the primary Pod to allow for |
253 | 282 | // commands to be run against it. |
254 | 283 | func getPrimaryExec(config *internal.Config, args []string) ( |
|
0 commit comments