| 105 | } |
| 106 | |
| 107 | func 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 | |
| 150 | func AskImportConfig(opts *ImportOptions) error { |
| 151 | // Validate file path |