MCPcopy Index your code
hub / github.com/devspace-sh/devspace / GetLanguage

Method GetLanguage

pkg/devspace/generator/language.go:131–179  ·  view source on GitHub ↗

GetLanguage gets the language from LanguageHandler either from its field "Language" or by detecting it

()

Source from the content-addressed store, hash-verified

129
130// GetLanguage gets the language from LanguageHandler either from its field "Language" or by detecting it
131func (cg *LanguageHandler) GetLanguage() (string, error) {
132 // If the language was determined already, return it from cache
133 if cg.Language != "" {
134 return cg.Language, nil
135 }
136
137 cg.log.WriteString(logrus.WarnLevel, "\n")
138 cg.log.Info("Detecting programming language...")
139
140 language, detectionErr := cg.detectLanguage()
141 if detectionErr != nil {
142 return "", detectionErr
143 }
144
145 supportedLanguages, err := cg.GetSupportedLanguages()
146 if err != nil {
147 cg.log.Warnf("Error retrieving support languages: %v", err)
148 }
149
150 if len(supportedLanguages) == 0 {
151 language = langFallback
152 } else {
153 otherOption := "other"
154 if language == langFallback {
155 language = otherOption
156 }
157
158 // Let the user select the language
159 language, err = cg.log.Question(&survey.QuestionOptions{
160 Question: "Select the programming language of this project",
161 DefaultValue: language,
162 Options: append(supportedLanguages, otherOption),
163 })
164 if err != nil {
165 return "", err
166 }
167
168 if language == otherOption {
169 language = langFallback
170 }
171 }
172
173 language = regexp.MustCompile(`^.*\((.*)\)$`).ReplaceAllString(language, "$1")
174
175 // Save user's choice in cache
176 cg.Language = language
177
178 return cg.Language, nil
179}
180
181// IsSupportedLanguage returns true if the given language is supported by the LanguageHandler
182func (cg *LanguageHandler) IsSupportedLanguage(language string) (bool, string) {

Callers 4

GetDevImageMethod · 0.95
CopyTemplatesMethod · 0.95
CopyFileMethod · 0.95
detectLanguageMethod · 0.80

Calls 6

detectLanguageMethod · 0.95
GetSupportedLanguagesMethod · 0.95
WriteStringMethod · 0.65
QuestionMethod · 0.65
InfoMethod · 0.45
WarnfMethod · 0.45

Tested by

no test coverage detected