1
0
mirror of https://github.com/alexellis/arkade.git synced 2022-05-07 18:22:49 +03:00

Add dry-run flag for preflight command

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2021-10-13 14:57:16 +01:00
parent 24ae742ec6
commit 40f23596a7

View File

@@ -28,11 +28,17 @@ func MakeInstallK10Preflight() *cobra.Command {
SilenceUsage: true,
}
k10cmd.Flags().Bool("dry-run", false, "Print the commands that would be run by the preflight script.")
k10cmd.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath, _ := command.Flags().GetString("kubeconfig")
if err := config.SetKubeconfig(kubeConfigPath); err != nil {
return err
}
dryRun, err := command.Flags().GetBool("dry-run")
if err != nil {
return err
}
primerURL := "https://docs.kasten.io/tools/k10_primer.sh"
req, err := http.NewRequest(http.MethodGet, primerURL, nil)
@@ -55,8 +61,15 @@ func MakeInstallK10Preflight() *cobra.Command {
if err := ioutil.WriteFile(outFile, body, 0755); err != nil {
return fmt.Errorf("error writing k10 preflight tool to: %s %w", outFile, err)
}
fmt.Printf("Downloaded %s to %s\n", primerURL, outFile)
if dryRun {
fmt.Printf("Preflight script contents:\n%s\n", string(body))
fmt.Printf("Run this command with --dry-run=false to execute the script.\n")
return nil
}
scriptRes, err := runScript(outFile)
if err != nil {
return err