MCPcopy Create free account
hub / github.com/algolia/cli / ValidateImportConfigFlags

Function ValidateImportConfigFlags

pkg/cmd/shared/handler/indices/config.go:107–148  ·  view source on GitHub ↗
(opts *ImportOptions)

Source from the content-addressed store, hash-verified

105}
106
107func ValidateImportConfigFlags(opts *ImportOptions) error {
108 cs := opts.IO.ColorScheme()
109
110 if opts.FilePath == "" {
111 return fmt.Errorf("%s Config file is required", cs.FailureIcon())
112 }
113
114 config, err := readConfigFromFile(cs, opts.FilePath)
115 if err != nil {
116 return err
117 }
118 opts.ImportConfig = *config
119
120 // Required flags
121 if len(opts.Scope) == 0 {
122 return fmt.Errorf("%s Scope is required", cs.FailureIcon())
123 }
124 // Scope and replace/clear existing options
125 if opts.ClearExistingRules && !utils.Contains(opts.Scope, "rules") {
126 return fmt.Errorf(
127 "%s Cannot clear existing rules if rules are not in scope",
128 cs.FailureIcon(),
129 )
130 }
131 if opts.ClearExistingSynonyms && !utils.Contains(opts.Scope, "synonyms") {
132 return fmt.Errorf(
133 "%s Cannot clear existing synonyms if synonyms are not in scope",
134 cs.FailureIcon(),
135 )
136 }
137 // Scope and config
138 if (utils.Contains(opts.Scope, "settings") && opts.ImportConfig.Settings != nil) ||
139 (utils.Contains(opts.Scope, "rules") && len(opts.ImportConfig.Rules) > 0) ||
140 (utils.Contains(opts.Scope, "synonyms") && len(opts.ImportConfig.Synonyms) > 0) {
141 return nil
142 }
143 return fmt.Errorf(
144 "%s No %s found in config file",
145 cs.FailureIcon(),
146 utils.SliceToReadableString(opts.Scope),
147 )
148}
149
150func AskImportConfig(opts *ImportOptions) error {
151 // Validate file path

Callers 1

Calls 6

ContainsFunction · 0.92
SliceToReadableStringFunction · 0.92
readConfigFromFileFunction · 0.85
ColorSchemeMethod · 0.80
FailureIconMethod · 0.80
ErrorfMethod · 0.65

Tested by 1