parseStringSliceFile returns a parser that reads a string slice from a file. It reads the file path from CLI args (--{cliArgName}) or falls back to the env var. Each line in the file becomes an entry. Empty lines and lines starting with # are ignored.
(env string)
| 251 | // It reads the file path from CLI args (--{cliArgName}) or falls back to the env var. |
| 252 | // Each line in the file becomes an entry. Empty lines and lines starting with # are ignored. |
| 253 | func parseStringSliceFile(env string) ([]string, error) { |
| 254 | // If no path provided, return empty slice |
| 255 | if env == "" { |
| 256 | return nil, nil |
| 257 | } |
| 258 | |
| 259 | content, err := os.ReadFile(env) |
| 260 | if err != nil { |
| 261 | return nil, fmt.Errorf("can't read file %s: %w", env, err) |
| 262 | } |
| 263 | |
| 264 | result := make([]string, 0) |
| 265 | |
| 266 | for line := range strings.SplitSeq(string(content), "\n") { |
| 267 | line = strings.TrimSpace(line) |
| 268 | if line == "" || strings.HasPrefix(line, "#") { |
| 269 | continue |
| 270 | } |
| 271 | result = append(result, line) |
| 272 | } |
| 273 | |
| 274 | return result, nil |
| 275 | } |
| 276 | |
| 277 | // parseURLReplacements parses URL replacements from the environment variable |
| 278 | func parseURLReplacements(env string) ([]URLReplacement, error) { |