version2 (#1)

Co-authored-by: u80864958 <niklas.breitenstein@bit.admin.ch>
Reviewed-on: #1
This commit is contained in:
2025-04-02 17:29:26 +02:00
parent abe9c7d1fb
commit 158e963c7b
11 changed files with 310 additions and 130 deletions

47
cmd/main.go Normal file
View File

@ -0,0 +1,47 @@
package main
import (
"flag"
"fmt"
"os"
"git.schreifuchs.ch/schreifuchs/pat/pkg/cat"
"git.schreifuchs.ch/schreifuchs/pat/pkg/clip"
"git.schreifuchs.ch/schreifuchs/pat/pkg/ignore"
)
const DELEMITTER = "-(%s)--------------------------------------------------------------------------\n"
func main() {
ignorePath := flag.String("i", "", "set path to gitignore, if no gitignore parent dirs will be searched")
hiddenFiles := flag.Bool("h", false, "show hidden files")
flag.Parse()
cats, err := cat.Path(flag.Args()...)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
if *ignorePath != "" {
i, err := ignore.FindGitignore(*ignorePath)
if err != nil {
fmt.Printf("can't get gitignore: %v", err)
os.Exit(1)
}
cats = cats.Ignored(i)
}
if *hiddenFiles == false {
cats = cats.Ignored(ignore.Filesystem{})
}
out := cats.ToString(DELEMITTER)
fmt.Print(out)
if err = clip.Copy(out); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}