mirror of
https://github.com/onyx-and-iris/exclude.git
synced 2026-04-16 14:13:39 +00:00
add del command
add tests for all commands wrap entry point with fang add --version flag target to Taskfile
This commit is contained in:
32
cmd/util.go
Normal file
32
cmd/util.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// readExistingPatterns reads the existing patterns from the exclude file, ignoring comments and empty lines
|
||||
func readExistingPatterns(f io.Reader) ([]string, error) {
|
||||
var patterns []string
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if line != "" && !strings.HasPrefix(line, "#") {
|
||||
patterns = append(patterns, line)
|
||||
}
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, fmt.Errorf("error scanning exclude file: %v", err)
|
||||
}
|
||||
return patterns, nil
|
||||
}
|
||||
|
||||
// writeDefaultExcludeContent writes the default exclude content to the writer
|
||||
func writeDefaultExcludeContent(w io.Writer) error {
|
||||
if _, err := w.Write([]byte(defaultExcludeFileContent)); err != nil {
|
||||
return fmt.Errorf("error writing default exclude file: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user