From c6f4d711875f790aaa4087ba9d971e9777a90928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Petr=C3=B3?= Date: Thu, 26 Aug 2021 15:56:08 +0200 Subject: [PATCH] Be able to create a git source without human interaction. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel PetrĂ³ --- cmd/flux/create_source_git.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/flux/create_source_git.go b/cmd/flux/create_source_git.go index 65790c0f..4e62dd34 100644 --- a/cmd/flux/create_source_git.go +++ b/cmd/flux/create_source_git.go @@ -56,6 +56,7 @@ type sourceGitFlags struct { caFile string privateKeyFile string recurseSubmodules bool + silent bool } var createSourceGitCmd = &cobra.Command{ @@ -135,6 +136,7 @@ func init() { createSourceGitCmd.Flags().StringVar(&sourceGitArgs.privateKeyFile, "private-key-file", "", "path to a passwordless private key file used for authenticating to the Git SSH server") createSourceGitCmd.Flags().BoolVar(&sourceGitArgs.recurseSubmodules, "recurse-submodules", false, "when enabled, configures the GitRepository source to initialize and include Git submodules in the artifact it produces") + createSourceGitCmd.Flags().BoolVarP(&sourceGitArgs.silent, "silent", "s", false, "assumes the deploy key is already setup, skips confirmation") createSourceCmd.AddCommand(createSourceGitCmd) } @@ -272,12 +274,14 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error { } if ppk, ok := s.StringData[sourcesecret.PublicKeySecretKey]; ok { logger.Generatef("deploy key: %s", ppk) - prompt := promptui.Prompt{ - Label: "Have you added the deploy key to your repository", - IsConfirm: true, - } - if _, err := prompt.Run(); err != nil { - return fmt.Errorf("aborting") + if !sourceGitArgs.silent { + prompt := promptui.Prompt{ + Label: "Have you added the deploy key to your repository", + IsConfirm: true, + } + if _, err := prompt.Run(); err != nil { + return fmt.Errorf("aborting") + } } } logger.Actionf("applying secret with repository credentials")