-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor module deprecation structs and function to own file
- Loading branch information
Showing
2 changed files
with
55 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package configs | ||
|
||
import "fmt" | ||
|
||
type WorkspaceDeprecations struct { | ||
ModuleDeprecationInfos []*ModuleDeprecationInfo | ||
} | ||
|
||
type ModuleDeprecationInfo struct { | ||
SourceName string | ||
RegistryDeprecation *RegistryModuleDeprecation | ||
ExternalDependencies []*ModuleDeprecationInfo | ||
} | ||
|
||
type RegistryModuleDeprecation struct { | ||
Version string | ||
ExternalLink string | ||
} | ||
|
||
func (i *WorkspaceDeprecations) BuildDeprecationWarningString() string { | ||
modDeprecationStrings := []string{} | ||
for _, modDeprecationInfo := range i.ModuleDeprecationInfos { | ||
if modDeprecationInfo.RegistryDeprecation != nil { | ||
modDeprecationStrings = append(modDeprecationStrings, fmt.Sprintf("Version %s of \"%s\" \nTo learn more visit: %s\n", modDeprecationInfo.RegistryDeprecation.Version, modDeprecationInfo.SourceName, modDeprecationInfo.RegistryDeprecation.ExternalLink)) | ||
} | ||
modDeprecationStrings = append(modDeprecationStrings, buildChildDeprecationWarnings(modDeprecationInfo.ExternalDependencies, []string{modDeprecationInfo.SourceName})...) | ||
} | ||
deprecationsMessage := "" | ||
for _, deprecationString := range modDeprecationStrings { | ||
deprecationsMessage += deprecationString + "\n" | ||
} | ||
|
||
return deprecationsMessage | ||
} | ||
|
||
func buildChildDeprecationWarnings(modDeprecations []*ModuleDeprecationInfo, parentMods []string) []string { | ||
modDeprecationStrings := []string{} | ||
for _, deprecation := range modDeprecations { | ||
if deprecation.RegistryDeprecation != nil { | ||
modDeprecationStrings = append(modDeprecationStrings, fmt.Sprintf("Version %s of \"%s\" %s \nTo learn more visit: %s\n", deprecation.RegistryDeprecation.Version, deprecation.SourceName, buildModHierarchy(parentMods, deprecation.SourceName), deprecation.RegistryDeprecation.ExternalLink)) | ||
} | ||
newParentMods := append(parentMods, deprecation.SourceName) | ||
modDeprecationStrings = append(modDeprecationStrings, buildChildDeprecationWarnings(deprecation.ExternalDependencies, newParentMods)...) | ||
} | ||
return modDeprecationStrings | ||
} | ||
|
||
func buildModHierarchy(parentMods []string, modName string) string { | ||
heirarchy := "" | ||
for _, parent := range parentMods { | ||
heirarchy += fmt.Sprintf("%s -> ", parent) | ||
} | ||
heirarchy += modName | ||
return fmt.Sprintf("(Root: %s)", heirarchy) | ||
} |