MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / AskGitResourceOverrideLoop

Function AskGitResourceOverrideLoop

pkg/gitresources/gitResources.go:68–174  ·  view source on GitHub ↗
(
	gitResourcesBaseline []*GitResourceGitRef,
	initialGitResourceOverrideFlags []string, // the --git-resource command line flag (multiple occurrences)
	asker question.Asker,
	stdout io.Writer)

Source from the content-addressed store, hash-verified

66const GitResourceOverrideQuestion = "Git resource git reference override string (y to accept, u to undo, r to reset, ? for help):"
67
68func AskGitResourceOverrideLoop(
69 gitResourcesBaseline []*GitResourceGitRef,
70 initialGitResourceOverrideFlags []string, // the --git-resource command line flag (multiple occurrences)
71 asker question.Asker,
72 stdout io.Writer) ([]*GitResourceGitRef, error) {
73
74 overriddenGitResourceGitRefs := make([]*GitResourceGitRef, 0)
75
76 // Parse the command line flags into overrides
77 for _, s := range initialGitResourceOverrideFlags {
78 //take the string from the command line and parse it into a GitResourceGitRef
79 parsedOverride, err := ParseGitResourceGitRefString(s)
80 if err != nil {
81 continue
82 }
83
84 resolvedOverride, err := ResolveGitResourceOverride(parsedOverride, gitResourcesBaseline)
85 if err != nil {
86 continue
87 }
88
89 overriddenGitResourceGitRefs = append(overriddenGitResourceGitRefs, resolvedOverride)
90 }
91
92 //now merge the parsed overrides with the baseline resources, applying any overrides that match
93 gitResourceGitRefsWithOverrides := ApplyGitResourceOverrides(gitResourcesBaseline, overriddenGitResourceGitRefs)
94
95outerLoop:
96 for {
97 err := printGitResourceGitRefs(stdout, gitResourceGitRefsWithOverrides)
98 if err != nil {
99 return nil, err
100 }
101
102 var resolvedOverride *GitResourceGitRef = nil
103 var answer = ""
104 err = asker(&survey.Input{
105 Message: GitResourceOverrideQuestion,
106 }, &answer, survey.WithValidator(func(ans interface{}) error {
107 str, ok := ans.(string)
108 if !ok {
109 return errors.New("internal error; answer was not a string")
110 }
111
112 switch str {
113 // valid response for continuing the loop; don't attempt to validate these
114 case "y", "u", "r", "?", "":
115 return nil
116 }
117
118 parsedOverride, err := ParseGitResourceGitRefString(str)
119 if err != nil {
120 return err
121 }
122
123 resolvedOverride, err = ResolveGitResourceOverride(parsedOverride, gitResourcesBaseline)
124 if err != nil {
125 return err

Callers 4

AskQuestionsFunction · 0.92
PromptMissingFunction · 0.92

Calls 6

FormatDocFunction · 0.92
printGitResourceGitRefsFunction · 0.85
EqualsMethod · 0.80