add del command

add tests for all commands

wrap entry point with fang

add --version flag
target to Taskfile
This commit is contained in:
2026-03-29 21:15:56 +01:00
parent 8f6a5d4472
commit 8059255d52
16 changed files with 520 additions and 80 deletions

View File

@@ -18,31 +18,36 @@ that are not empty and do not start with a comment (#).
This is useful for reviewing which files or directories are currently excluded from version control.`,
Args: cobra.NoArgs, // No arguments expected
RunE: func(cmd *cobra.Command, args []string) error {
f, ok := FileFromContext(cmd.Context())
ctx, ok := ContextObjectFromContext(cmd.Context())
if !ok {
return fmt.Errorf("no exclude file found in context")
}
return runListCommand(f, args)
return runListCommand(ctx.Out, ctx.File)
},
}
func init() {
rootCmd.AddCommand(listCmd)
RootCmd.AddCommand(listCmd)
}
// runListCommand is the function that will be executed when the list command is called
func runListCommand(f io.Reader, _ []string) error {
// Read from the exclude file line by line
func runListCommand(out io.Writer, f io.Reader) error {
var count int
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
if line != "" && !strings.HasPrefix(line, "#") {
fmt.Println(line) // Print each non-empty, non-comment line
fmt.Fprintln(out, line)
count++
}
}
if err := scanner.Err(); err != nil {
return fmt.Errorf("error reading exclude file: %w", err)
}
if count == 0 {
fmt.Fprintln(out, "No patterns found in the exclude file.")
}
return nil
}