1
0
mirror of synced 2026-02-13 13:06:56 +00:00

feat: add --ignore-paths flag to flux create source (git|bucket)

A new --ignore-paths flag is added to following commands:

flux create source git --ignore-paths ...
flux create source bucket --ignore-paths ...

A StringSliceVar is used which supports specifying the flag multiple
times to populate a list or either a comma seperated string value

A unit test with a golden file is added to validate the flag

Signed-off-by: Tarun Gupta Akirala <takirala@users.noreply.github.com>
This commit is contained in:
Tarun Gupta Akirala
2022-05-24 16:52:54 -07:00
parent 5ebb985b10
commit ed88e9dec5
4 changed files with 70 additions and 10 deletions

View File

@@ -22,6 +22,7 @@ import (
"fmt"
"net/url"
"os"
"strings"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
@@ -59,6 +60,7 @@ type sourceGitFlags struct {
privateKeyFile string
recurseSubmodules bool
silent bool
ignorePaths []string
}
var createSourceGitCmd = &cobra.Command{
@@ -139,6 +141,7 @@ func init() {
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")
createSourceGitCmd.Flags().StringSliceVar(&sourceGitArgs.ignorePaths, "ignore-paths", nil, "set paths to ignore in git resource (can specify multiple paths with commas: path1,path2)")
createSourceCmd.AddCommand(createSourceGitCmd)
}
@@ -189,6 +192,12 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
return err
}
var ignorePaths *string
if len(sourceGitArgs.ignorePaths) > 0 {
ignorePathsStr := strings.Join(sourceGitArgs.ignorePaths, "\n")
ignorePaths = &ignorePathsStr
}
gitRepository := sourcev1.GitRepository{
ObjectMeta: metav1.ObjectMeta{
Name: name,
@@ -202,6 +211,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
},
RecurseSubmodules: sourceGitArgs.recurseSubmodules,
Reference: &sourcev1.GitRepositoryRef{},
Ignore: ignorePaths,
},
}