mirror of
https://github.com/onyx-and-iris/exclude.git
synced 2026-04-16 14:13:39 +00:00
exclude initial commit
This commit is contained in:
41
cmd/add.go
Normal file
41
cmd/add.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// addCmd represents the add command
|
||||
var addCmd = &cobra.Command{
|
||||
Use: "add",
|
||||
Short: "Add patterns to the exclude file",
|
||||
Long: `The add command allows you to add one or more patterns to the .git/info/exclude file.
|
||||
This is useful for excluding files or directories from version control without modifying the .gitignore file.`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
f, ok := FileFromContext(cmd.Context())
|
||||
if !ok {
|
||||
return fmt.Errorf("no exclude file found in context")
|
||||
}
|
||||
return runAddCommand(f, args)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(addCmd)
|
||||
}
|
||||
|
||||
func runAddCommand(f io.Writer, args []string) error {
|
||||
for _, pattern := range args {
|
||||
if _, err := fmt.Fprintln(f, pattern); err != nil {
|
||||
return fmt.Errorf("error writing to exclude file: %w", err)
|
||||
}
|
||||
}
|
||||
fmt.Println("Patterns added to .git/info/exclude file:")
|
||||
for _, pattern := range args {
|
||||
fmt.Println(" -", pattern)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user