├── internal ├── utils │ ├── file_unix.go │ ├── clipboard.go │ ├── file_windows.go │ ├── patterns.go │ └── filesystem.go ├── formatter │ ├── markdown.go │ ├── xml.go │ └── formatter.go ├── config │ └── config.go ├── scanner │ └── scanner.go ├── security │ └── checker.go └── git │ └── repository.go ├── go.mod ├── README.md ├── cmd └── diffdeck │ └── main.go ├── go.sum └── LICENSE /internal/utils/file_unix.go: -------------------------------------------------------------------------------- 1 | //go:build !windows 2 | package utils 3 | 4 | import ( 5 | "path/filepath" 6 | "strings" 7 | ) 8 | 9 | func IsHiddenFile(path string) bool { 10 | filename := filepath.Base(path) 11 | return strings.HasPrefix(filename, ".") 12 | } -------------------------------------------------------------------------------- /internal/utils/clipboard.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | 7 | "github.com/atotto/clipboard" 8 | ) 9 | 10 | func CopyToClipboard(text string) error { 11 | if clipboard.Unsupported { 12 | return fmt.Errorf("clipboard operations not supported on %s", runtime.GOOS) 13 | } 14 | return clipboard.WriteAll(text) 15 | } 16 | -------------------------------------------------------------------------------- /internal/utils/file_windows.go: -------------------------------------------------------------------------------- 1 | //go:build windows 2 | package utils 3 | 4 | //go:generate mkwinsyscall -output zsyscall_windows.go file_windows.go 5 | 6 | import ( 7 | "golang.org/x/sys/windows" 8 | ) 9 | 10 | func IsHiddenFile(path string) bool { 11 | pointer, err := windows.UTF16PtrFromString(path) 12 | if err != nil { 13 | return false 14 | } 15 | attributes, err := windows.GetFileAttributes(pointer) 16 | if err != nil { 17 | return false 18 | } 19 | return attributes&windows.FILE_ATTRIBUTE_HIDDEN != 0 20 | } 21 | -------------------------------------------------------------------------------- /internal/utils/patterns.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "path/filepath" 5 | "strings" 6 | ) 7 | 8 | func ParsePatternList(patterns string) []string { 9 | if patterns == "" { 10 | return nil 11 | } 12 | 13 | var result []string 14 | for _, p := range strings.Split(patterns, ",") { 15 | if pattern := strings.TrimSpace(p); pattern != "" { 16 | result = append(result, pattern) 17 | } 18 | } 19 | return result 20 | } 21 | 22 | func MatchesAny(path string, patterns []string) bool { 23 | if len(patterns) == 0 { 24 | return false 25 | } 26 | 27 | path = filepath.Clean(path) 28 | for _, pattern := range patterns { 29 | if matched, _ := filepath.Match(pattern, path); matched { 30 | return true 31 | } 32 | if strings.HasPrefix(pattern, "**/") { 33 | if matched, _ := filepath.Match(pattern[3:], path); matched { 34 | return true 35 | } 36 | } 37 | } 38 | return false 39 | } 40 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/KnockOutEZ/diffdeck 2 | 3 | go 1.22.2 4 | 5 | require ( 6 | github.com/atotto/clipboard v0.1.4 7 | github.com/bmatcuk/doublestar v1.3.4 8 | github.com/bmatcuk/doublestar/v4 v4.7.1 9 | github.com/go-git/go-git/v5 v5.13.0 10 | github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d 11 | github.com/schollz/progressbar/v3 v3.17.1 12 | golang.org/x/sys v0.28.0 13 | golang.org/x/text v0.21.0 14 | ) 15 | 16 | require ( 17 | dario.cat/mergo v1.0.0 // indirect 18 | github.com/Microsoft/go-winio v0.6.1 // indirect 19 | github.com/ProtonMail/go-crypto v1.1.3 // indirect 20 | github.com/cloudflare/circl v1.3.7 // indirect 21 | github.com/cyphar/filepath-securejoin v0.2.5 // indirect 22 | github.com/emirpasic/gods v1.18.1 // indirect 23 | github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect 24 | github.com/go-git/go-billy/v5 v5.6.0 // indirect 25 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect 26 | github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect 27 | github.com/kevinburke/ssh_config v1.2.0 // indirect 28 | github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect 29 | github.com/pjbgf/sha1cd v0.3.0 // indirect 30 | github.com/rivo/uniseg v0.4.7 // indirect 31 | github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect 32 | github.com/skeema/knownhosts v1.3.0 // indirect 33 | github.com/xanzy/ssh-agent v0.3.3 // indirect 34 | golang.org/x/crypto v0.31.0 // indirect 35 | golang.org/x/mod v0.17.0 // indirect 36 | golang.org/x/net v0.33.0 // indirect 37 | golang.org/x/sync v0.10.0 // indirect 38 | golang.org/x/term v0.27.0 // indirect 39 | golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect 40 | gopkg.in/warnings.v0 v0.1.2 // indirect 41 | ) 42 | -------------------------------------------------------------------------------- /internal/formatter/markdown.go: -------------------------------------------------------------------------------- 1 | package formatter 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "time" 7 | "github.com/KnockOutEZ/diffdeck/internal/git" 8 | ) 9 | 10 | type MarkdownFormatter struct { 11 | opts Options 12 | } 13 | 14 | func (f *MarkdownFormatter) Format(changes []git.FileChange) (string, error) { 15 | var buf strings.Builder 16 | 17 | buf.WriteString("# Diffdeck Output\n\n") 18 | buf.WriteString(fmt.Sprintf("Generated: %s\n\n", time.Now().Format(time.RFC3339))) 19 | 20 | buf.WriteString("## Summary\n\n") 21 | buf.WriteString(fmt.Sprintf("- Total changes: %d\n", len(changes))) 22 | buf.WriteString(fmt.Sprintf("- Diff mode: %s\n\n", f.opts.DiffMode)) 23 | 24 | buf.WriteString("## Changes\n\n") 25 | for _, change := range changes { 26 | buf.WriteString(fmt.Sprintf("### %s\n\n", change.Path)) 27 | buf.WriteString(fmt.Sprintf("- Status: `%s`\n", change.Status)) 28 | buf.WriteString(fmt.Sprintf("- Language: `%s`\n", change.Language)) 29 | if change.Status == git.Renamed { 30 | buf.WriteString(fmt.Sprintf("- Old path: `%s`\n", change.OldPath)) 31 | } 32 | buf.WriteString("\n") 33 | 34 | switch f.opts.DiffMode { 35 | case "unified": 36 | diff := generateUnifiedDiff(change.OldContent, change.Content, f.opts.ShowLineNumbers) 37 | buf.WriteString("```diff\n") 38 | buf.WriteString(diff) 39 | buf.WriteString("```\n\n") 40 | case "side-by-side": 41 | diff := generateSideBySideDiff(change.OldContent, change.Content, f.opts.ShowLineNumbers) 42 | buf.WriteString("```\n") 43 | buf.WriteString(diff) 44 | buf.WriteString("```\n\n") 45 | default: 46 | buf.WriteString("```") 47 | if change.Language != "Unknown" { 48 | buf.WriteString(strings.ToLower(change.Language)) 49 | } 50 | buf.WriteString("\n") 51 | buf.WriteString(change.Content) 52 | buf.WriteString("```\n\n") 53 | } 54 | } 55 | 56 | return buf.String(), nil 57 | } -------------------------------------------------------------------------------- /internal/formatter/xml.go: -------------------------------------------------------------------------------- 1 | package formatter 2 | 3 | import ( 4 | "encoding/xml" 5 | "fmt" 6 | "time" 7 | "github.com/KnockOutEZ/diffdeck/internal/git" 8 | ) 9 | 10 | type XMLFormatter struct { 11 | opts Options 12 | } 13 | 14 | type XMLOutput struct { 15 | XMLName xml.Name `xml:"diffdeck"` 16 | Generated string `xml:"generated,attr"` 17 | Summary XMLSummary `xml:"summary"` 18 | Changes []XMLChange `xml:"changes>change"` 19 | } 20 | 21 | type XMLSummary struct { 22 | TotalFiles int `xml:"totalFiles"` 23 | DiffMode string `xml:"diffMode"` 24 | } 25 | 26 | type XMLChange struct { 27 | Path string `xml:"path,attr"` 28 | OldPath string `xml:"oldPath,omitempty"` 29 | Status string `xml:"status"` 30 | Language string `xml:"language"` 31 | OldContent string `xml:"oldContent,omitempty"` 32 | NewContent string `xml:"newContent,omitempty"` 33 | Diff string `xml:"diff,omitempty"` 34 | } 35 | 36 | func (f *XMLFormatter) Format(changes []git.FileChange) (string, error) { 37 | output := XMLOutput{ 38 | Generated: time.Now().Format(time.RFC3339), 39 | Summary: XMLSummary{ 40 | TotalFiles: len(changes), 41 | DiffMode: f.opts.DiffMode, 42 | }, 43 | } 44 | 45 | for _, change := range changes { 46 | xmlChange := XMLChange{ 47 | Path: change.Path, 48 | OldPath: change.OldPath, 49 | Status: string(change.Status), 50 | Language: change.Language, 51 | } 52 | 53 | switch f.opts.DiffMode { 54 | case "unified": 55 | xmlChange.Diff = generateUnifiedDiff(change.OldContent, change.Content, f.opts.ShowLineNumbers) 56 | case "side-by-side": 57 | xmlChange.Diff = generateSideBySideDiff(change.OldContent, change.Content, f.opts.ShowLineNumbers) 58 | default: 59 | xmlChange.OldContent = change.OldContent 60 | xmlChange.NewContent = change.Content 61 | } 62 | 63 | output.Changes = append(output.Changes, xmlChange) 64 | } 65 | 66 | data, err := xml.MarshalIndent(output, "", " ") 67 | if err != nil { 68 | return "", fmt.Errorf("failed to marshal XML: %w", err) 69 | } 70 | 71 | return xml.Header + string(data), nil 72 | } 73 | -------------------------------------------------------------------------------- /internal/config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "encoding/json" 5 | "os" 6 | "path/filepath" 7 | ) 8 | 9 | type Config struct { 10 | Output struct { 11 | FilePath string `json:"filePath"` 12 | Style string `json:"style"` 13 | ShowLineNumbers bool `json:"showLineNumbers"` 14 | CopyToClipboard bool `json:"copyToClipboard"` 15 | TopFilesLength int `json:"topFilesLength"` 16 | } `json:"output"` 17 | 18 | Include []string `json:"include"` 19 | Ignore struct { 20 | Patterns []string `json:"patterns"` 21 | } `json:"ignore"` 22 | 23 | Security struct { 24 | DisableSecurityCheck bool `json:"disableSecurityCheck"` 25 | MaxFileSize int64 `json:"maxFileSize"` 26 | } `json:"security"` 27 | 28 | Git struct { 29 | DefaultRemote string `json:"defaultRemote"` 30 | CacheDir string `json:"cacheDir"` 31 | Timeout string `json:"timeout"` 32 | } `json:"git"` 33 | } 34 | 35 | func DefaultConfig() *Config { 36 | cfg := &Config{} 37 | 38 | cfg.Output.FilePath = "diffdeck-output.txt" 39 | cfg.Output.Style = "plain" 40 | cfg.Output.ShowLineNumbers = false 41 | cfg.Output.CopyToClipboard = false 42 | cfg.Output.TopFilesLength = 5 43 | 44 | cfg.Include = []string{"**/*"} 45 | cfg.Ignore.Patterns = []string{ 46 | ".git/**", 47 | ".github/**", 48 | "node_modules/**", 49 | "vendor/**", 50 | "dist/**", 51 | "build/**", 52 | "*.exe", 53 | "*.dll", 54 | "*.so", 55 | "*.dylib", 56 | "*.test", 57 | "*.out", 58 | "*.log", 59 | "*.tmp", 60 | "*.temp", 61 | ".DS_Store", 62 | "Thumbs.db", 63 | "**/.git/**", 64 | "**/node_modules/**", 65 | "**/vendor/**", 66 | "**/.idea/**", 67 | "**/.vscode/**", 68 | } 69 | 70 | cfg.Security.DisableSecurityCheck = false 71 | cfg.Security.MaxFileSize = 10 * 1024 * 1024 // 10MB 72 | 73 | cfg.Git.CacheDir = filepath.Join(os.TempDir(), "diffdeck-cache") 74 | cfg.Git.Timeout = "5m" 75 | 76 | return cfg 77 | } 78 | 79 | func Load(path string) (*Config, error) { 80 | cfg := DefaultConfig() 81 | 82 | data, err := os.ReadFile(path) 83 | if err != nil { 84 | if os.IsNotExist(err) { 85 | return cfg, nil 86 | } 87 | return nil, err 88 | } 89 | 90 | if err := json.Unmarshal(data, cfg); err != nil { 91 | return nil, err 92 | } 93 | 94 | return cfg, nil 95 | } 96 | 97 | func (c *Config) Save(path string) error { 98 | data, err := json.MarshalIndent(c, "", " ") 99 | if err != nil { 100 | return err 101 | } 102 | 103 | return os.WriteFile(path, data, 0644) 104 | } 105 | -------------------------------------------------------------------------------- /internal/utils/filesystem.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "os" 7 | "strings" 8 | 9 | "github.com/saintfish/chardet" 10 | "golang.org/x/text/encoding" 11 | "golang.org/x/text/encoding/unicode" 12 | ) 13 | 14 | type FileInfo struct { 15 | Path string 16 | Size int64 17 | ModTime int64 18 | IsDir bool 19 | IsSymlink bool 20 | IsHidden bool 21 | MimeType string 22 | Encoding string 23 | LineCount int 24 | IsText bool 25 | IsExecutable bool 26 | } 27 | 28 | func GetFileInfo(path string) (*FileInfo, error) { 29 | info, err := os.Lstat(path) 30 | if err != nil { 31 | return nil, err 32 | } 33 | 34 | fi := &FileInfo{ 35 | Path: path, 36 | Size: info.Size(), 37 | ModTime: info.ModTime().Unix(), 38 | IsDir: info.IsDir(), 39 | } 40 | 41 | fi.IsSymlink = info.Mode()&os.ModeSymlink != 0 42 | 43 | fi.IsHidden = IsHiddenFile(path) 44 | 45 | fi.IsExecutable = info.Mode()&0111 != 0 46 | 47 | if !fi.IsDir && !fi.IsSymlink { 48 | content, err := os.ReadFile(path) 49 | if err != nil { 50 | return fi, nil 51 | } 52 | 53 | mtype, isText := DetectMimeType(content) 54 | fi.MimeType = mtype 55 | fi.IsText = isText 56 | 57 | if fi.IsText { 58 | fi.Encoding, _ = DetectEncoding(content) 59 | fi.LineCount = CountLines(content) 60 | } 61 | } 62 | 63 | return fi, nil 64 | } 65 | 66 | func DetectMimeType(content []byte) (string, bool) { 67 | buffer := content 68 | if len(buffer) > 512 { 69 | buffer = buffer[:512] 70 | } 71 | 72 | mtype := http.DetectContentType(buffer) 73 | isText := strings.HasPrefix(mtype, "text/") || 74 | mtype == "application/json" || 75 | mtype == "application/xml" || 76 | mtype == "application/javascript" 77 | 78 | return mtype, isText 79 | } 80 | 81 | func DetectEncoding(content []byte) (string, error) { 82 | detector := chardet.NewTextDetector() 83 | result, err := detector.DetectBest(content) 84 | if err != nil { 85 | return "", err 86 | } 87 | return result.Charset, nil 88 | } 89 | 90 | func ReadFileWithEncoding(path string, encodingName string) (string, error) { 91 | content, err := os.ReadFile(path) 92 | if err != nil { 93 | return "", err 94 | } 95 | 96 | var decoder *encoding.Decoder 97 | switch strings.ToLower(encodingName) { 98 | case "utf-8", "utf8": 99 | return string(content), nil 100 | case "utf-16le": 101 | decoder = unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM).NewDecoder() 102 | case "utf-16be": 103 | decoder = unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM).NewDecoder() 104 | default: 105 | return "", fmt.Errorf("unsupported encoding: %s", encodingName) 106 | } 107 | 108 | decoded, err := decoder.Bytes(content) 109 | if err != nil { 110 | return "", err 111 | } 112 | 113 | return string(decoded), nil 114 | } 115 | 116 | func CountLines(content []byte) int { 117 | if len(content) == 0 { 118 | return 0 119 | } 120 | 121 | count := 0 122 | for _, b := range content { 123 | if b == '\n' { 124 | count++ 125 | } 126 | } 127 | 128 | if content[len(content)-1] != '\n' { 129 | count++ 130 | } 131 | 132 | return count 133 | } 134 | 135 | -------------------------------------------------------------------------------- /internal/formatter/formatter.go: -------------------------------------------------------------------------------- 1 | package formatter 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "strings" 7 | "github.com/KnockOutEZ/diffdeck/internal/git" 8 | ) 9 | 10 | type Options struct { 11 | Style string 12 | ShowLineNumbers bool 13 | TopFilesLength int 14 | DiffMode string 15 | } 16 | 17 | type Formatter interface { 18 | Format(changes []git.FileChange) (string, error) 19 | } 20 | 21 | func NewFormatter(opts Options) Formatter { 22 | switch opts.Style { 23 | case "markdown": 24 | return &MarkdownFormatter{opts: opts} 25 | case "xml": 26 | return &XMLFormatter{opts: opts} 27 | default: 28 | return &PlainFormatter{opts: opts} 29 | } 30 | } 31 | 32 | type PlainFormatter struct { 33 | opts Options 34 | } 35 | 36 | func (f *PlainFormatter) Format(changes []git.FileChange) (string, error) { 37 | var buf bytes.Buffer 38 | 39 | buf.WriteString("Diffdeck Output\n") 40 | buf.WriteString("==============\n\n") 41 | 42 | buf.WriteString(fmt.Sprintf("Total changes: %d\n", len(changes))) 43 | buf.WriteString(fmt.Sprintf("Diff mode: %s\n\n", f.opts.DiffMode)) 44 | 45 | for _, change := range changes { 46 | buf.WriteString(fmt.Sprintf("File: %s\n", change.Path)) 47 | buf.WriteString(fmt.Sprintf("Status: %s\n", change.Status)) 48 | if change.Status == git.Renamed { 49 | buf.WriteString(fmt.Sprintf("Old path: %s\n", change.OldPath)) 50 | } 51 | buf.WriteString("----------------------------------------\n") 52 | 53 | switch f.opts.DiffMode { 54 | case "unified": 55 | diff := generateUnifiedDiff(change.OldContent, change.Content, f.opts.ShowLineNumbers) 56 | buf.WriteString(diff) 57 | case "side-by-side": 58 | diff := generateSideBySideDiff(change.OldContent, change.Content, f.opts.ShowLineNumbers) 59 | buf.WriteString(diff) 60 | default: 61 | buf.WriteString(change.Content) 62 | } 63 | 64 | buf.WriteString("\n\n") 65 | } 66 | 67 | return buf.String(), nil 68 | } 69 | 70 | func generateUnifiedDiff(oldContent, newContent string, showLineNumbers bool) string { 71 | if oldContent == "" { 72 | return newContent 73 | } 74 | 75 | var buf bytes.Buffer 76 | oldLines := strings.Split(oldContent, "\n") 77 | newLines := strings.Split(newContent, "\n") 78 | 79 | for i := 0; i < len(oldLines) || i < len(newLines); i++ { 80 | if i < len(oldLines) && i < len(newLines) { 81 | if oldLines[i] != newLines[i] { 82 | if showLineNumbers { 83 | buf.WriteString(fmt.Sprintf("-%d: %s\n", i+1, oldLines[i])) 84 | buf.WriteString(fmt.Sprintf("+%d: %s\n", i+1, newLines[i])) 85 | } else { 86 | buf.WriteString(fmt.Sprintf("-%s\n", oldLines[i])) 87 | buf.WriteString(fmt.Sprintf("+%s\n", newLines[i])) 88 | } 89 | } else { 90 | if showLineNumbers { 91 | buf.WriteString(fmt.Sprintf(" %d: %s\n", i+1, oldLines[i])) 92 | } else { 93 | buf.WriteString(fmt.Sprintf(" %s\n", oldLines[i])) 94 | } 95 | } 96 | } else if i < len(oldLines) { 97 | if showLineNumbers { 98 | buf.WriteString(fmt.Sprintf("-%d: %s\n", i+1, oldLines[i])) 99 | } else { 100 | buf.WriteString(fmt.Sprintf("-%s\n", oldLines[i])) 101 | } 102 | } else { 103 | if showLineNumbers { 104 | buf.WriteString(fmt.Sprintf("+%d: %s\n", i+1, newLines[i])) 105 | } else { 106 | buf.WriteString(fmt.Sprintf("+%s\n", newLines[i])) 107 | } 108 | } 109 | } 110 | 111 | return buf.String() 112 | } 113 | 114 | func generateSideBySideDiff(oldContent, newContent string, showLineNumbers bool) string { 115 | var buf bytes.Buffer 116 | oldLines := strings.Split(oldContent, "\n") 117 | newLines := strings.Split(newContent, "\n") 118 | 119 | maxWidth := 80 120 | separator := " | " 121 | 122 | for i := 0; i < len(oldLines) || i < len(newLines); i++ { 123 | var leftLine, rightLine string 124 | 125 | if i < len(oldLines) { 126 | leftLine = oldLines[i] 127 | } 128 | if i < len(newLines) { 129 | rightLine = newLines[i] 130 | } 131 | 132 | if showLineNumbers { 133 | leftNum := fmt.Sprintf("%4d", i+1) 134 | rightNum := fmt.Sprintf("%4d", i+1) 135 | buf.WriteString(fmt.Sprintf("%s: %-*s %s %s: %s\n", 136 | leftNum, maxWidth, leftLine, separator, rightNum, rightLine)) 137 | } else { 138 | buf.WriteString(fmt.Sprintf("%-*s %s %s\n", 139 | maxWidth, leftLine, separator, rightLine)) 140 | } 141 | } 142 | 143 | return buf.String() 144 | } 145 | -------------------------------------------------------------------------------- /internal/scanner/scanner.go: -------------------------------------------------------------------------------- 1 | package scanner 2 | 3 | import ( 4 | "fmt" 5 | "io/fs" 6 | "os" 7 | "path/filepath" 8 | "strings" 9 | "sync" 10 | 11 | "github.com/KnockOutEZ/diffdeck/internal/config" 12 | "github.com/bmatcuk/doublestar/v4" 13 | "github.com/schollz/progressbar/v3" 14 | ) 15 | 16 | type File struct { 17 | Path string 18 | Content string 19 | Size int64 20 | IsDir bool 21 | Children []File 22 | } 23 | 24 | type Scanner struct { 25 | progress *progressbar.ProgressBar 26 | config *config.Config 27 | maxSize int64 28 | mu sync.Mutex 29 | wg sync.WaitGroup 30 | semaphore chan struct{} 31 | } 32 | 33 | func NewScanner(cfg *config.Config, progress *progressbar.ProgressBar) *Scanner { 34 | return &Scanner{ 35 | config: cfg, 36 | progress: progress, 37 | maxSize: cfg.Security.MaxFileSize, 38 | semaphore: make(chan struct{}, 10), 39 | } 40 | } 41 | 42 | func (s *Scanner) Scan(paths []string) ([]File, error) { 43 | var files []File 44 | for _, path := range paths { 45 | stat, err := os.Stat(path) 46 | if err != nil { 47 | return nil, fmt.Errorf("failed to stat %s: %w", path, err) 48 | } 49 | 50 | if stat.IsDir() { 51 | dirFiles, err := s.scanDirectory(path) 52 | if err != nil { 53 | return nil, err 54 | } 55 | files = append(files, dirFiles...) 56 | } else { 57 | if !s.shouldIgnore(path) { 58 | file, err := s.scanFile(path) 59 | if err != nil { 60 | return nil, err 61 | } 62 | files = append(files, file) 63 | } 64 | } 65 | } 66 | 67 | s.wg.Wait() 68 | return files, nil 69 | } 70 | 71 | func (s *Scanner) scanDirectory(root string) ([]File, error) { 72 | var files []File 73 | var mu sync.Mutex 74 | 75 | err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error { 76 | if err != nil { 77 | return err 78 | } 79 | 80 | relPath, err := filepath.Rel(root, path) 81 | if err != nil { 82 | return err 83 | } 84 | 85 | if relPath == "." { 86 | return nil 87 | } 88 | 89 | if s.shouldIgnore(relPath) { 90 | if d.IsDir() { 91 | return filepath.SkipDir 92 | } 93 | return nil 94 | } 95 | 96 | if !s.shouldInclude(relPath) { 97 | if d.IsDir() { 98 | return filepath.SkipDir 99 | } 100 | return nil 101 | } 102 | 103 | if !d.IsDir() { 104 | s.wg.Add(1) 105 | go func() { 106 | defer s.wg.Done() 107 | s.semaphore <- struct{}{} 108 | defer func() { <-s.semaphore }() 109 | 110 | file, err := s.scanFile(path) 111 | if err != nil { 112 | fmt.Fprintf(os.Stderr, "Error scanning %s: %v\n", path, err) 113 | return 114 | } 115 | 116 | mu.Lock() 117 | files = append(files, file) 118 | mu.Unlock() 119 | 120 | if s.progress != nil { 121 | s.progress.Add(1) 122 | } 123 | }() 124 | } 125 | 126 | return nil 127 | }) 128 | 129 | return files, err 130 | } 131 | 132 | func (s *Scanner) shouldIgnore(path string) bool { 133 | path = filepath.ToSlash(path) 134 | 135 | for _, pattern := range s.config.Ignore.Patterns { 136 | pattern = filepath.ToSlash(pattern) 137 | 138 | if strings.HasPrefix(pattern, "**/") { 139 | if matched, _ := doublestar.Match(pattern, path); matched { 140 | return true 141 | } 142 | } else if strings.Contains(pattern, "**") { 143 | if matched, _ := doublestar.Match(pattern, path); matched { 144 | return true 145 | } 146 | } else { 147 | if matched, _ := filepath.Match(pattern, filepath.Base(path)); matched { 148 | return true 149 | } 150 | } 151 | } 152 | 153 | return false 154 | } 155 | 156 | func (s *Scanner) shouldInclude(path string) bool { 157 | if len(s.config.Include) == 0 { 158 | return true 159 | } 160 | 161 | path = filepath.ToSlash(path) 162 | for _, pattern := range s.config.Include { 163 | pattern = filepath.ToSlash(pattern) 164 | if matched, _ := doublestar.Match(pattern, path); matched { 165 | return true 166 | } 167 | } 168 | 169 | return false 170 | } 171 | 172 | func (s *Scanner) scanFile(path string) (File, error) { 173 | info, err := os.Stat(path) 174 | if err != nil { 175 | return File{}, err 176 | } 177 | 178 | file := File{ 179 | Path: path, 180 | IsDir: info.IsDir(), 181 | Size: info.Size(), 182 | } 183 | 184 | if !file.IsDir && file.Size <= s.maxSize { 185 | content, err := os.ReadFile(path) 186 | if err != nil { 187 | return file, err 188 | } 189 | file.Content = string(content) 190 | } 191 | 192 | return file, nil 193 | } -------------------------------------------------------------------------------- /internal/security/checker.go: -------------------------------------------------------------------------------- 1 | package security 2 | 3 | import ( 4 | "fmt" 5 | "regexp" 6 | "strings" 7 | "sync" 8 | 9 | "github.com/KnockOutEZ/diffdeck/internal/git" 10 | "github.com/schollz/progressbar/v3" 11 | ) 12 | 13 | type Options struct { 14 | MaxFileSize int64 15 | Progress *progressbar.ProgressBar 16 | CustomPatterns map[string]string 17 | SkipBinaries bool 18 | Severity string 19 | } 20 | 21 | type Issue struct { 22 | FilePath string 23 | Line int 24 | Column int 25 | Rule string 26 | Description string 27 | Severity string 28 | Content string 29 | } 30 | 31 | type Checker struct { 32 | patterns map[string]*regexp.Regexp 33 | progress *progressbar.ProgressBar 34 | maxSize int64 35 | skipBinaries bool 36 | severity string 37 | mu sync.Mutex 38 | } 39 | 40 | func NewChecker(opts Options) *Checker { 41 | patterns := defaultPatterns() 42 | 43 | if opts.CustomPatterns != nil { 44 | for name, pattern := range opts.CustomPatterns { 45 | compiled, err := regexp.Compile(pattern) 46 | if err == nil { 47 | patterns[name] = compiled 48 | } 49 | } 50 | } 51 | 52 | return &Checker{ 53 | patterns: patterns, 54 | progress: opts.Progress, 55 | maxSize: opts.MaxFileSize, 56 | skipBinaries: opts.SkipBinaries, 57 | severity: opts.Severity, 58 | } 59 | } 60 | 61 | func (c *Checker) Check(changes []git.FileChange) ([]Issue, error) { 62 | var issues []Issue 63 | var wg sync.WaitGroup 64 | semaphore := make(chan struct{}, 10) // Limit concurrent checks 65 | 66 | for _, change := range changes { 67 | wg.Add(1) 68 | go func(fc git.FileChange) { 69 | defer wg.Done() 70 | semaphore <- struct{}{} // Acquire 71 | defer func() { <-semaphore }() // Release 72 | 73 | fileIssues := c.checkFile(fc) 74 | 75 | c.mu.Lock() 76 | issues = append(issues, fileIssues...) 77 | c.mu.Unlock() 78 | 79 | if c.progress != nil { 80 | c.progress.Add(1) 81 | } 82 | }(change) 83 | } 84 | 85 | wg.Wait() 86 | return issues, nil 87 | } 88 | 89 | func (c *Checker) checkFile(change git.FileChange) []Issue { 90 | var issues []Issue 91 | 92 | if int64(len(change.Content)) > c.maxSize { 93 | return issues 94 | } 95 | 96 | isGoFile := strings.HasSuffix(change.Path, ".go") 97 | 98 | lines := strings.Split(change.Content, "\n") 99 | inImportBlock := false 100 | 101 | for lineNum, line := range lines { 102 | if isGoFile { 103 | if strings.HasPrefix(strings.TrimSpace(line), "import (") { 104 | inImportBlock = true 105 | continue 106 | } 107 | if inImportBlock { 108 | if strings.HasPrefix(strings.TrimSpace(line), ")") { 109 | inImportBlock = false 110 | } 111 | continue 112 | } 113 | } 114 | 115 | for name, pattern := range c.patterns { 116 | matches := pattern.FindAllStringIndex(line, -1) 117 | for _, match := range matches { 118 | start, end := match[0], match[1] 119 | 120 | if isGoFile && strings.Contains(line[:start], "import") { 121 | continue 122 | } 123 | 124 | contextStart := max(0, start-20) 125 | contextEnd := min(len(line), end+20) 126 | context := line[contextStart:contextEnd] 127 | 128 | issues = append(issues, Issue{ 129 | FilePath: change.Path, 130 | Line: lineNum + 1, 131 | Column: start + 1, 132 | Rule: name, 133 | Description: fmt.Sprintf("Found potential %s", name), 134 | Severity: "WARNING", 135 | Content: context, 136 | }) 137 | } 138 | } 139 | } 140 | 141 | return issues 142 | } 143 | 144 | func max(a, b int) int { 145 | if a > b { 146 | return a 147 | } 148 | return b 149 | } 150 | 151 | func min(a, b int) int { 152 | if a < b { 153 | return a 154 | } 155 | return b 156 | } 157 | 158 | func defaultPatterns() map[string]*regexp.Regexp { 159 | return map[string]*regexp.Regexp{ 160 | "AWS Access Key": regexp.MustCompile(`(?i)AKIA[0-9A-Z]{16}`), 161 | "AWS Secret Key": regexp.MustCompile(`(?i)(aws_secret|aws_key|aws_token|aws_access).{0,20}[A-Za-z0-9/+=]{40}`), 162 | "Private Key": regexp.MustCompile(`-----BEGIN (?:RSA |DSA |EC )?PRIVATE KEY-----`), 163 | "SSH Private Key": regexp.MustCompile(`-----BEGIN OPENSSH PRIVATE KEY-----`), 164 | "GitHub Token": regexp.MustCompile(`(?i)(github|gh)[0-9a-zA-Z_-]*token[ :="\']([0-9a-zA-Z]{35,40})`), 165 | "Google API Key": regexp.MustCompile(`AIza[0-9A-Za-z\-_]{35}`), 166 | "Password in Code": regexp.MustCompile(`(?i)(?:password|passwd|pwd)[ :=]+['"][^'"\n]{8,}['"]`), 167 | "API Key in Code": regexp.MustCompile(`(?i)(?:api[_-]?key|api[_-]?secret|api[_-]?token)[ :=]+['"][^'"\n]{8,}['"]`), 168 | "IP Address": regexp.MustCompile(`(?:^|\s|=)(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9])(?:\s|$)`), 169 | "Internal URL": regexp.MustCompile(`(?i)(?:localhost|127\.0\.0\.1|0\.0\.0\.0):\d+`), 170 | } 171 | } 172 | 173 | func findPosition(content string, offset int) (line, column int) { 174 | line = 1 175 | column = 1 176 | for i := 0; i < offset; i++ { 177 | if content[i] == '\n' { 178 | line++ 179 | column = 1 180 | } else { 181 | column++ 182 | } 183 | } 184 | return 185 | } 186 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DiffDeck 2 | 3 | DiffDeck is a powerful, flexible code difference analysis tool that helps developers understand, document, and secure their code changes. It provides rich diff visualization, security scanning, and various output formats to suit different needs. 4 | 5 | [![Go Report Card](https://goreportcard.com/badge/github.com/KnockOutEZ/diffdeck)](https://goreportcard.com/report/github.com/KnockOutEZ/diffdeck) 6 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 7 | 8 | ## Features 9 | 10 | - 🔍 **Smart Diff Analysis**: Compare branches, commits, or local files with intelligent diff algorithms 11 | - 🛡️ **Security Scanning**: Built-in security checks for sensitive data and potential vulnerabilities 12 | - 📊 **Multiple Output Formats**: Support for plain text, Markdown, MDX, and XML outputs 13 | - 🎨 **Customizable Styling**: Line numbers, custom headers, and formatting options 14 | - 🚀 **Performance Optimized**: Efficient processing of large codebases 15 | - 🔒 **Security First**: Automatic scanning for sensitive data and security issues 16 | - 📋 **Clipboard Integration**: Direct copying of diff output to clipboard 17 | 18 | ## Installation 19 | 20 | ```bash 21 | go install github.com/KnockOutEZ/diffdeck/cmd/diffdeck@latest 22 | ``` 23 | 24 | Or build from source: 25 | 26 | ```bash 27 | git clone https://github.com/KnockOutEZ/diffdeck.git 28 | cd diffdeck 29 | go build ./cmd/diffdeck 30 | ``` 31 | 32 | ## Quick Start 33 | 34 | 1. Compare two branches: 35 | ```bash 36 | diffdeck --from-branch develop --to-branch main 37 | ``` 38 | 39 | 2. Compare with custom output: 40 | ```bash 41 | diffdeck --from-branch develop --to-branch main --output diff.md --style markdown 42 | ``` 43 | 44 | 3. Enable security scanning: 45 | ```bash 46 | diffdeck --from-branch develop --to-branch main --security-check 47 | ``` 48 | 49 | ## Configuration 50 | 51 | DiffDeck can be configured via JSON configuration file. Default location is `diffdeck.config.json`. 52 | 53 | ### Basic Configuration Example: 54 | 55 | ```json 56 | { 57 | "output": { 58 | "filePath": "diffdeck-output.txt", 59 | "style": "mdx", 60 | "showLineNumbers": true, 61 | "copyToClipboard": true, 62 | "topFilesLength": 5 63 | }, 64 | "include": ["**/*"], 65 | "ignore": { 66 | "patterns": [ 67 | ".git/**", 68 | "node_modules/**", 69 | "vendor/**" 70 | ] 71 | }, 72 | "security": { 73 | "disableSecurityCheck": false, 74 | "maxFileSize": 10485760 75 | } 76 | } 77 | ``` 78 | 79 | ### Configuration Options Explained 80 | 81 | #### Output Configuration 82 | ```json 83 | "output": { 84 | "filePath": "diffdeck-output.txt", // Output file path 85 | "style": "mdx", // Output format: plain, markdown, mdx, xml 86 | "showLineNumbers": true, // Include line numbers in diff 87 | "copyToClipboard": true, // Copy output to clipboard 88 | "topFilesLength": 5 // Number of files in summary 89 | } 90 | ``` 91 | 92 | #### File Patterns 93 | ```json 94 | "include": ["**/*"], // Files to include 95 | "ignore": { 96 | "patterns": [ // Files to ignore 97 | ".git/**", 98 | "node_modules/**", 99 | "vendor/**" 100 | ] 101 | } 102 | ``` 103 | 104 | #### Security Settings 105 | ```json 106 | "security": { 107 | "disableSecurityCheck": false, // Enable/disable security scanning 108 | "maxFileSize": 10485760 // Max file size to scan (10MB) 109 | } 110 | ``` 111 | 112 | #### Git Settings 113 | ```json 114 | "git": { 115 | "defaultRemote": "", // Default remote repository 116 | "cacheDir": "/tmp/cache", // Cache directory location 117 | "timeout": "5m" // Git operation timeout 118 | } 119 | ``` 120 | 121 | ## Command Line Usage 122 | 123 | ### Basic Commands 124 | 125 | ```bash 126 | # Compare branches 127 | diffdeck --from-branch feature --to-branch main 128 | 129 | # Use specific config file 130 | diffdeck --config my-config.json --from-branch feature --to-branch main 131 | 132 | # Generate markdown output 133 | diffdeck --style markdown --output diff.md --from-branch feature --to-branch main 134 | 135 | # Disable security checks 136 | diffdeck --no-security-check --from-branch feature --to-branch main 137 | 138 | # Show line numbers 139 | diffdeck --show-line-numbers --from-branch feature --to-branch main 140 | ``` 141 | 142 | ### Advanced Usage 143 | 144 | ```bash 145 | # Custom include/ignore patterns 146 | diffdeck --include "src/**/*.js" --ignore "**/*.test.js" 147 | 148 | # Set custom file size limit 149 | diffdeck --max-file-size 20971520 150 | 151 | # Compare specific files 152 | diffdeck --files "src/main.js,src/utils.js" 153 | 154 | # Use custom cache directory 155 | diffdeck --cache-dir "/custom/cache/path" 156 | ``` 157 | 158 | ## Output Formats 159 | 160 | ### Plain Text 161 | ```bash 162 | diffdeck --style plain 163 | ``` 164 | Generates simple text output with basic formatting. 165 | 166 | ### Markdown 167 | ```bash 168 | diffdeck --style markdown 169 | ``` 170 | Generates GitHub-flavored Markdown with syntax highlighting. 171 | 172 | ### MDX 173 | ```bash 174 | diffdeck --style mdx 175 | ``` 176 | Generates MDX format suitable for React documentation. 177 | 178 | ### XML 179 | ```bash 180 | diffdeck --style xml 181 | ``` 182 | Generates structured XML output for programmatic processing. 183 | 184 | ## Security Scanning 185 | 186 | DiffDeck includes built-in security scanning capabilities: 187 | 188 | - Sensitive data detection (API keys, tokens) 189 | - Password pattern matching 190 | - Private key detection 191 | - Internal URL/IP detection 192 | - AWS credentials scanning 193 | 194 | Enable/disable security scanning: 195 | ```bash 196 | # Enable 197 | diffdeck --security-check 198 | 199 | # Disable 200 | diffdeck --no-security-check 201 | ``` 202 | 203 | ## File Pattern Syntax 204 | 205 | DiffDeck uses glob patterns for file matching: 206 | 207 | - `**/*` - Match all files 208 | - `*.{js,ts}` - Match JavaScript and TypeScript files 209 | - `src/**/*.go` - Match Go files in src directory 210 | - `!test/**` - Exclude test directory 211 | 212 | ## Performance Tips 213 | 214 | 1. Use appropriate `maxFileSize` limit 215 | 2. Leverage ignore patterns for large directories 216 | 3. Use cache directory for repeated operations 217 | 4. Consider disabling security checks for large diffs 218 | 5. Use specific include patterns when possible 219 | 220 | ## Integration Examples 221 | 222 | ### GitHub Actions 223 | ```yaml 224 | - name: Run DiffDeck 225 | run: | 226 | diffdeck --from-branch ${{ github.event.pull_request.base.ref }} \ 227 | --to-branch ${{ github.event.pull_request.head.ref }} \ 228 | --output diff.md \ 229 | --style markdown 230 | ``` 231 | 232 | ### GitLab CI 233 | ```yaml 234 | diff_check: 235 | script: 236 | - diffdeck --from-branch $CI_MERGE_REQUEST_TARGET_BRANCH_NAME \ 237 | --to-branch $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME \ 238 | --style markdown \ 239 | --output diff.md 240 | ``` 241 | 242 | ## Common Issues and Solutions 243 | 244 | 1. **Large Files** 245 | - Increase `maxFileSize` in config 246 | - Use more specific include patterns 247 | 248 | 2. **Performance Issues** 249 | - Optimize ignore patterns 250 | - Use cache directory 251 | - Consider disabling security checks 252 | 253 | 3. **Git Integration** 254 | - Ensure correct branch names 255 | - Check timeout settings 256 | - Verify git credentials 257 | 258 | ## Contributing 259 | 260 | 1. Fork the repository 261 | 2. Create your feature branch 262 | 3. Commit your changes 263 | 4. Push to the branch 264 | 5. Create a Pull Request 265 | 266 | ## License 267 | 268 | MIT License - see LICENSE file for details. -------------------------------------------------------------------------------- /internal/git/repository.go: -------------------------------------------------------------------------------- 1 | package git 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "os" 7 | "path/filepath" 8 | "time" 9 | 10 | "github.com/bmatcuk/doublestar" 11 | "github.com/go-git/go-git/v5" 12 | "github.com/go-git/go-git/v5/plumbing" 13 | "github.com/go-git/go-git/v5/plumbing/object" 14 | "github.com/schollz/progressbar/v3" 15 | ) 16 | 17 | type ChangeStatus string 18 | 19 | const ( 20 | Added ChangeStatus = "added" 21 | Modified ChangeStatus = "modified" 22 | Deleted ChangeStatus = "deleted" 23 | Renamed ChangeStatus = "renamed" 24 | Unmodified ChangeStatus = "unmodified" 25 | ) 26 | 27 | type FileChange struct { 28 | Path string 29 | OldPath string 30 | Content string 31 | OldContent string 32 | Status ChangeStatus 33 | Language string 34 | } 35 | 36 | type DiffOptions struct { 37 | FromBranch string 38 | ToBranch string 39 | FromCommit string 40 | ToCommit string 41 | DiffMode string 42 | ContextLines int 43 | } 44 | 45 | type CloneOptions struct { 46 | URL string 47 | Branch string 48 | CacheDir string 49 | Timeout time.Duration 50 | Progress *progressbar.ProgressBar 51 | } 52 | 53 | type Repository struct { 54 | url string 55 | localPath string 56 | repo *git.Repository 57 | isTemp bool 58 | progress *progressbar.ProgressBar 59 | options RepositoryOptions 60 | } 61 | 62 | func NewLocalRepository(path string, progress *progressbar.ProgressBar, opts RepositoryOptions) (*Repository, error) { 63 | repo, err := git.PlainOpen(path) 64 | if err != nil { 65 | return nil, fmt.Errorf("failed to open repository: %w", err) 66 | } 67 | 68 | return &Repository{ 69 | localPath: path, 70 | repo: repo, 71 | progress: progress, 72 | options: opts, 73 | }, nil 74 | } 75 | 76 | func NewRemoteRepository(opts CloneOptions) (*Repository, error) { 77 | if err := os.MkdirAll(opts.CacheDir, 0755); err != nil { 78 | return nil, fmt.Errorf("failed to create cache directory: %w", err) 79 | } 80 | 81 | tempDir, err := os.MkdirTemp(opts.CacheDir, "repo-*") 82 | if err != nil { 83 | return nil, fmt.Errorf("failed to create temporary directory: %w", err) 84 | } 85 | 86 | r := &Repository{ 87 | url: opts.URL, 88 | localPath: tempDir, 89 | isTemp: true, 90 | progress: opts.Progress, 91 | } 92 | 93 | cloneOpts := &git.CloneOptions{ 94 | URL: opts.URL, 95 | Progress: progressWriter{opts.Progress}, 96 | SingleBranch: true, 97 | Depth: 1, 98 | } 99 | 100 | if opts.Branch != "" { 101 | cloneOpts.ReferenceName = plumbing.NewBranchReferenceName(opts.Branch) 102 | } 103 | 104 | ctx, cancel := context.WithTimeout(context.Background(), opts.Timeout) 105 | defer cancel() 106 | 107 | repo, err := git.PlainCloneContext(ctx, tempDir, false, cloneOpts) 108 | if err != nil { 109 | os.RemoveAll(tempDir) 110 | return nil, fmt.Errorf("failed to clone repository: %w", err) 111 | } 112 | 113 | r.repo = repo 114 | return r, nil 115 | } 116 | 117 | func (r *Repository) Close() error { 118 | if r.isTemp && r.localPath != "" { 119 | return os.RemoveAll(r.localPath) 120 | } 121 | return nil 122 | } 123 | 124 | type RepositoryOptions struct { 125 | IgnorePatterns []string 126 | IncludePatterns []string 127 | Progress *progressbar.ProgressBar 128 | } 129 | 130 | func (r *Repository) CompareBranches(opts DiffOptions) ([]FileChange, error) { 131 | fromRef, err := r.repo.Reference(plumbing.NewBranchReferenceName(opts.FromBranch), true) 132 | if err != nil { 133 | return nil, fmt.Errorf("failed to get source branch reference: %w", err) 134 | } 135 | 136 | toRef, err := r.repo.Reference(plumbing.NewBranchReferenceName(opts.ToBranch), true) 137 | if err != nil { 138 | return nil, fmt.Errorf("failed to get target branch reference: %w", err) 139 | } 140 | 141 | fromCommit, err := r.repo.CommitObject(fromRef.Hash()) 142 | if err != nil { 143 | return nil, fmt.Errorf("failed to get source commit: %w", err) 144 | } 145 | 146 | toCommit, err := r.repo.CommitObject(toRef.Hash()) 147 | if err != nil { 148 | return nil, fmt.Errorf("failed to get target commit: %w", err) 149 | } 150 | 151 | patch, err := fromCommit.Patch(toCommit) 152 | if err != nil { 153 | return nil, fmt.Errorf("failed to get patch: %w", err) 154 | } 155 | 156 | var changes []FileChange 157 | for _, filePatch := range patch.FilePatches() { 158 | from, to := filePatch.Files() 159 | 160 | if to != nil { 161 | if shouldIgnoreFile(to.Path(), r.options.IgnorePatterns) || !shouldIncludeFile(to.Path(), r.options.IncludePatterns) { 162 | continue 163 | } 164 | } 165 | if from != nil { 166 | if shouldIgnoreFile(from.Path(), r.options.IgnorePatterns) || !shouldIncludeFile(from.Path(), r.options.IncludePatterns) { 167 | continue 168 | } 169 | } 170 | 171 | change := FileChange{} 172 | 173 | switch { 174 | case from == nil && to != nil: 175 | change.Status = Added 176 | change.Path = to.Path() 177 | change.Content = getFileContent(r.repo, toCommit, to.Path()) 178 | 179 | case from != nil && to == nil: 180 | change.Status = Deleted 181 | change.Path = from.Path() 182 | change.OldContent = getFileContent(r.repo, fromCommit, from.Path()) 183 | 184 | case from != nil && to != nil: 185 | if from.Path() != to.Path() { 186 | change.Status = Renamed 187 | change.OldPath = from.Path() 188 | change.Path = to.Path() 189 | } else { 190 | change.Status = Modified 191 | change.Path = to.Path() 192 | } 193 | change.OldContent = getFileContent(r.repo, fromCommit, from.Path()) 194 | change.Content = getFileContent(r.repo, toCommit, to.Path()) 195 | } 196 | 197 | change.Language = detectLanguage(change.Path) 198 | changes = append(changes, change) 199 | 200 | if r.progress != nil { 201 | r.progress.Add(1) 202 | } 203 | } 204 | 205 | return changes, nil 206 | } 207 | 208 | func (r *Repository) GetChanges(opts DiffOptions) ([]FileChange, error) { 209 | if opts.FromBranch != "" && opts.ToBranch != "" { 210 | return r.CompareBranches(opts) 211 | } 212 | 213 | head, err := r.repo.Head() 214 | if err != nil { 215 | return nil, fmt.Errorf("failed to get repository head: %w", err) 216 | } 217 | 218 | commit, err := r.repo.CommitObject(head.Hash()) 219 | if err != nil { 220 | return nil, fmt.Errorf("failed to get commit: %w", err) 221 | } 222 | 223 | var changes []FileChange 224 | files, err := commit.Files() 225 | if err != nil { 226 | return nil, fmt.Errorf("failed to get files: %w", err) 227 | } 228 | 229 | err = files.ForEach(func(f *object.File) error { 230 | if shouldIgnoreFile(f.Name, r.options.IgnorePatterns) { 231 | return nil 232 | } 233 | 234 | content, err := f.Contents() 235 | if err != nil { 236 | return err 237 | } 238 | 239 | changes = append(changes, FileChange{ 240 | Path: f.Name, 241 | Content: content, 242 | Status: Unmodified, 243 | Language: detectLanguage(f.Name), 244 | }) 245 | return nil 246 | }) 247 | 248 | return changes, err 249 | } 250 | 251 | func shouldIgnoreFile(path string, ignorePatterns []string) bool { 252 | if len(ignorePatterns) == 0 { 253 | return false 254 | } 255 | 256 | path = filepath.ToSlash(path) 257 | for _, pattern := range ignorePatterns { 258 | pattern = filepath.ToSlash(pattern) 259 | if matched, _ := doublestar.Match(pattern, path); matched { 260 | return true 261 | } 262 | } 263 | return false 264 | } 265 | 266 | func getFileContent(repo *git.Repository, commit *object.Commit, path string) string { 267 | file, err := commit.File(path) 268 | if err != nil { 269 | return "" 270 | } 271 | 272 | content, err := file.Contents() 273 | if err != nil { 274 | return "" 275 | } 276 | 277 | return content 278 | } 279 | 280 | func detectLanguage(path string) string { 281 | ext := filepath.Ext(path) 282 | switch ext { 283 | case ".go": 284 | return "Go" 285 | case ".js": 286 | return "JavaScript" 287 | case ".py": 288 | return "Python" 289 | case ".java": 290 | return "Java" 291 | case ".cpp", ".cc", ".cxx": 292 | return "C++" 293 | case ".cs": 294 | return "C#" 295 | case ".rb": 296 | return "Ruby" 297 | case ".php": 298 | return "PHP" 299 | case ".swift": 300 | return "Swift" 301 | case ".rs": 302 | return "Rust" 303 | case ".kt": 304 | return "Kotlin" 305 | case ".ts": 306 | return "TypeScript" 307 | default: 308 | return "Unknown" 309 | } 310 | } 311 | 312 | type progressWriter struct { 313 | bar *progressbar.ProgressBar 314 | } 315 | 316 | func (pw progressWriter) Write(p []byte) (n int, err error) { 317 | if pw.bar != nil { 318 | pw.bar.Add(len(p)) 319 | } 320 | return len(p), nil 321 | } 322 | 323 | func shouldIncludeFile(path string, includePatterns []string) bool { 324 | if len(includePatterns) == 0 { 325 | return true 326 | } 327 | 328 | path = filepath.ToSlash(path) 329 | for _, pattern := range includePatterns { 330 | pattern = filepath.ToSlash(pattern) 331 | if matched, _ := doublestar.Match(pattern, path); matched { 332 | return true 333 | } 334 | } 335 | return false 336 | } 337 | -------------------------------------------------------------------------------- /cmd/diffdeck/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | "path/filepath" 8 | "time" 9 | 10 | "github.com/KnockOutEZ/diffdeck/internal/config" 11 | "github.com/KnockOutEZ/diffdeck/internal/formatter" 12 | "github.com/KnockOutEZ/diffdeck/internal/git" 13 | "github.com/KnockOutEZ/diffdeck/internal/scanner" 14 | "github.com/KnockOutEZ/diffdeck/internal/security" 15 | "github.com/KnockOutEZ/diffdeck/internal/utils" 16 | "github.com/schollz/progressbar/v3" 17 | ) 18 | 19 | var ( 20 | version = "1.0.0" 21 | 22 | // Command line flags 23 | configPath string 24 | outputPath string 25 | outputStyle string 26 | includePatterns string 27 | ignorePatterns string 28 | remoteURL string 29 | remoteBranch string 30 | fromBranch string 31 | toBranch string 32 | diffMode string 33 | cacheDir string 34 | showVersion bool 35 | initConfig bool 36 | topFilesLen int 37 | showLineNumbers bool 38 | copyToClipboard bool 39 | noSecurityCheck bool 40 | verbose bool 41 | progressBar bool 42 | maxFileSize int64 43 | timeout time.Duration 44 | ) 45 | 46 | func init() { 47 | // Basic flags 48 | flag.StringVar(&configPath, "config", "", "Path to config file") 49 | flag.StringVar(&outputPath, "output", "", "Output file path") 50 | flag.StringVar(&outputStyle, "style", "plain", "Output style (plain, xml, markdown)") 51 | flag.StringVar(&includePatterns, "include", "", "Include patterns (comma-separated)") 52 | flag.StringVar(&ignorePatterns, "ignore", "", "Ignore patterns (comma-separated)") 53 | 54 | // Git-related flags 55 | flag.StringVar(&remoteURL, "remote", "", "Remote repository URL") 56 | flag.StringVar(&remoteBranch, "remote-branch", "", "Remote branch, tag, or commit") 57 | flag.StringVar(&fromBranch, "from-branch", "", "Source branch for comparison") 58 | flag.StringVar(&toBranch, "to-branch", "", "Target branch for comparison") 59 | flag.StringVar(&diffMode, "diff-mode", "unified", "Diff display mode (unified or side-by-side)") 60 | flag.StringVar(&cacheDir, "cache-dir", filepath.Join(os.TempDir(), "diffdeck-cache"), "Cache directory for remote repositories") 61 | 62 | // Output control flags 63 | flag.BoolVar(&showVersion, "version", false, "Show version") 64 | flag.BoolVar(&initConfig, "init", false, "Initialize config file") 65 | flag.IntVar(&topFilesLen, "top-files-len", 5, "Number of top files to display") 66 | flag.BoolVar(&showLineNumbers, "show-line-numbers", false, "Show line numbers") 67 | flag.BoolVar(©ToClipboard, "copy", false, "Copy output to clipboard") 68 | flag.BoolVar(&noSecurityCheck, "no-security-check", false, "Disable security check") 69 | flag.BoolVar(&verbose, "verbose", false, "Enable verbose logging") 70 | flag.BoolVar(&progressBar, "progress", true, "Show progress bar") 71 | flag.Int64Var(&maxFileSize, "max-file-size", 10*1024*1024, "Maximum file size in bytes") 72 | flag.DurationVar(&timeout, "timeout", 5*time.Minute, "Timeout for remote operations") 73 | 74 | // Short versions 75 | flag.StringVar(&outputPath, "o", "", "Output file path (shorthand)") 76 | flag.StringVar(&configPath, "c", "", "Config file path (shorthand)") 77 | flag.StringVar(&ignorePatterns, "i", "", "Ignore patterns (shorthand)") 78 | flag.BoolVar(&showVersion, "v", false, "Show version (shorthand)") 79 | } 80 | 81 | func main() { 82 | startTime := time.Now() 83 | flag.Parse() 84 | 85 | if err := run(); err != nil { 86 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) 87 | os.Exit(1) 88 | } 89 | 90 | if verbose { 91 | fmt.Printf("Total execution time: %v\n", time.Since(startTime)) 92 | } 93 | } 94 | 95 | func run() error { 96 | if showVersion { 97 | fmt.Printf("diffdeck version %s\n", version) 98 | return nil 99 | } 100 | 101 | if initConfig { 102 | return initializeConfig() 103 | } 104 | 105 | cfg, err := loadConfig() 106 | if err != nil { 107 | return fmt.Errorf("failed to load config: %w", err) 108 | } 109 | 110 | applyCommandLineOverrides(cfg) 111 | 112 | var bar *progressbar.ProgressBar 113 | if progressBar { 114 | bar = progressbar.NewOptions(-1, 115 | progressbar.OptionSetDescription("Processing"), 116 | progressbar.OptionSetItsString("files"), 117 | progressbar.OptionShowCount(), 118 | progressbar.OptionShowIts(), 119 | progressbar.OptionSetTheme(progressbar.Theme{ 120 | Saucer: "=", 121 | SaucerHead: ">", 122 | SaucerPadding: " ", 123 | BarStart: "[", 124 | BarEnd: "]", 125 | }), 126 | ) 127 | } 128 | 129 | var changes []git.FileChange 130 | if remoteURL != "" { 131 | changes, err = processRemoteRepository(bar) 132 | } else if fromBranch != "" && toBranch != "" { 133 | changes, err = processLocalBranchComparison(bar, cfg) 134 | } else { 135 | changes, err = processLocalFiles(cfg, bar) 136 | } 137 | if err != nil { 138 | return err 139 | } 140 | 141 | if !cfg.Security.DisableSecurityCheck { 142 | if err := runSecurityCheck(changes, bar); err != nil { 143 | return err 144 | } 145 | } 146 | 147 | output, err := formatOutput(changes, cfg) 148 | if err != nil { 149 | return err 150 | } 151 | 152 | return writeOutput(output, cfg) 153 | } 154 | 155 | func processRemoteRepository(bar *progressbar.ProgressBar) ([]git.FileChange, error) { 156 | opts := git.CloneOptions{ 157 | URL: remoteURL, 158 | Branch: remoteBranch, 159 | CacheDir: cacheDir, 160 | Timeout: timeout, 161 | Progress: bar, 162 | } 163 | 164 | repo, err := git.NewRemoteRepository(opts) 165 | if err != nil { 166 | return nil, fmt.Errorf("failed to create repository: %w", err) 167 | } 168 | defer repo.Close() 169 | 170 | return repo.GetChanges(git.DiffOptions{ 171 | FromBranch: fromBranch, 172 | ToBranch: toBranch, 173 | DiffMode: diffMode, 174 | }) 175 | } 176 | 177 | func processLocalBranchComparison(bar *progressbar.ProgressBar, cfg *config.Config) ([]git.FileChange, error) { 178 | repo, err := git.NewLocalRepository(".", bar, git.RepositoryOptions{ 179 | IgnorePatterns: cfg.Ignore.Patterns, 180 | IncludePatterns: cfg.Include, 181 | Progress: bar, 182 | }) 183 | if err != nil { 184 | return nil, fmt.Errorf("failed to open local repository: %w", err) 185 | } 186 | defer repo.Close() 187 | 188 | return repo.CompareBranches(git.DiffOptions{ 189 | FromBranch: fromBranch, 190 | ToBranch: toBranch, 191 | DiffMode: diffMode, 192 | }) 193 | } 194 | 195 | func processLocalFiles(cfg *config.Config, bar *progressbar.ProgressBar) ([]git.FileChange, error) { 196 | paths := flag.Args() 197 | if len(paths) == 0 { 198 | paths = []string{"."} 199 | } 200 | 201 | s := scanner.NewScanner(cfg, bar) 202 | files, err := s.Scan(paths) 203 | if err != nil { 204 | return nil, fmt.Errorf("failed to scan files: %w", err) 205 | } 206 | 207 | var changes []git.FileChange 208 | for _, f := range files { 209 | if utils.MatchesAny(f.Path, cfg.Ignore.Patterns) { 210 | continue 211 | } 212 | 213 | changes = append(changes, git.FileChange{ 214 | Path: f.Path, 215 | Content: f.Content, 216 | Status: git.Unmodified, 217 | }) 218 | } 219 | 220 | return changes, nil 221 | } 222 | 223 | func runSecurityCheck(changes []git.FileChange, bar *progressbar.ProgressBar) error { 224 | checker := security.NewChecker(security.Options{ 225 | MaxFileSize: maxFileSize, 226 | Progress: bar, 227 | SkipBinaries: true, 228 | Severity: "WARNING", 229 | }) 230 | 231 | issues, err := checker.Check(changes) 232 | if err != nil { 233 | return fmt.Errorf("security check failed: %w", err) 234 | } 235 | 236 | if len(issues) > 0 { 237 | fmt.Fprintln(os.Stderr, "\nSecurity Issues Found:") 238 | for _, issue := range issues { 239 | fmt.Fprintf(os.Stderr, "- %s:%d: [%s] %s\n", 240 | issue.FilePath, 241 | issue.Line, 242 | issue.Rule, 243 | issue.Description) 244 | } 245 | fmt.Fprintln(os.Stderr) 246 | } 247 | 248 | return nil 249 | } 250 | 251 | func formatOutput(changes []git.FileChange, cfg *config.Config) (string, error) { 252 | f := formatter.NewFormatter(formatter.Options{ 253 | Style: cfg.Output.Style, 254 | ShowLineNumbers: cfg.Output.ShowLineNumbers, 255 | TopFilesLength: cfg.Output.TopFilesLength, 256 | DiffMode: diffMode, 257 | }) 258 | 259 | return f.Format(changes) 260 | } 261 | 262 | func writeOutput(output string, cfg *config.Config) error { 263 | if cfg.Output.FilePath != "" { 264 | if err := os.WriteFile(cfg.Output.FilePath, []byte(output), 0644); err != nil { 265 | return fmt.Errorf("failed to write output file: %w", err) 266 | } 267 | } 268 | 269 | if cfg.Output.CopyToClipboard { 270 | if err := utils.CopyToClipboard(output); err != nil { 271 | return fmt.Errorf("failed to copy to clipboard: %w", err) 272 | } 273 | } 274 | 275 | if cfg.Output.FilePath == "" { 276 | fmt.Print(output) 277 | } 278 | 279 | return nil 280 | } 281 | 282 | func loadConfig() (*config.Config, error) { 283 | if configPath == "" { 284 | configPath = "diffdeck.config.json" 285 | } 286 | return config.Load(configPath) 287 | } 288 | 289 | func initializeConfig() error { 290 | cfg := config.DefaultConfig() 291 | return cfg.Save("diffdeck.config.json") 292 | } 293 | 294 | func applyCommandLineOverrides(cfg *config.Config) { 295 | if outputPath != "" { 296 | cfg.Output.FilePath = outputPath 297 | } 298 | if outputStyle != "" { 299 | cfg.Output.Style = outputStyle 300 | } 301 | if includePatterns != "" { 302 | cfg.Include = utils.ParsePatternList(includePatterns) 303 | } 304 | if ignorePatterns != "" { 305 | cfg.Ignore.Patterns = utils.ParsePatternList(ignorePatterns) 306 | } 307 | if showLineNumbers { 308 | cfg.Output.ShowLineNumbers = true 309 | } 310 | if copyToClipboard { 311 | cfg.Output.CopyToClipboard = true 312 | } 313 | if noSecurityCheck { 314 | cfg.Security.DisableSecurityCheck = true 315 | } 316 | if topFilesLen > 0 { 317 | cfg.Output.TopFilesLength = topFilesLen 318 | } 319 | } 320 | 321 | func logVerbose(format string, args ...interface{}) { 322 | if verbose { 323 | fmt.Fprintf(os.Stderr, format+"\n", args...) 324 | } 325 | } 326 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= 2 | dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= 3 | github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= 4 | github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= 5 | github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= 6 | github.com/ProtonMail/go-crypto v1.1.3 h1:nRBOetoydLeUb4nHajyO2bKqMLfWQ/ZPwkXqXxPxCFk= 7 | github.com/ProtonMail/go-crypto v1.1.3/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= 8 | github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= 9 | github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= 10 | github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= 11 | github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= 12 | github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= 13 | github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= 14 | github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0= 15 | github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE= 16 | github.com/bmatcuk/doublestar/v4 v4.7.1 h1:fdDeAqgT47acgwd9bd9HxJRDmc9UAmPpc+2m0CXv75Q= 17 | github.com/bmatcuk/doublestar/v4 v4.7.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= 18 | github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM= 19 | github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY= 20 | github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= 21 | github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= 22 | github.com/cyphar/filepath-securejoin v0.2.5 h1:6iR5tXJ/e6tJZzzdMc1km3Sa7RRIVBKAK32O2s7AYfo= 23 | github.com/cyphar/filepath-securejoin v0.2.5/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= 24 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 25 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 26 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 27 | github.com/elazarl/goproxy v1.2.1 h1:njjgvO6cRG9rIqN2ebkqy6cQz2Njkx7Fsfv/zIZqgug= 28 | github.com/elazarl/goproxy v1.2.1/go.mod h1:YfEbZtqP4AetfO6d40vWchF3znWX7C7Vd6ZMfdL8z64= 29 | github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= 30 | github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= 31 | github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c= 32 | github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU= 33 | github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= 34 | github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= 35 | github.com/go-git/go-billy/v5 v5.6.0 h1:w2hPNtoehvJIxR00Vb4xX94qHQi/ApZfX+nBE2Cjio8= 36 | github.com/go-git/go-billy/v5 v5.6.0/go.mod h1:sFDq7xD3fn3E0GOwUSZqHo9lrkmx8xJhA0ZrfvjBRGM= 37 | github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= 38 | github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= 39 | github.com/go-git/go-git/v5 v5.13.0 h1:vLn5wlGIh/X78El6r3Jr+30W16Blk0CTcxTYcYPWi5E= 40 | github.com/go-git/go-git/v5 v5.13.0/go.mod h1:Wjo7/JyVKtQgUNdXYXIepzWfJQkUEIGvkvVkiXRR/zw= 41 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= 42 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 43 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 44 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 45 | github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= 46 | github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= 47 | github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= 48 | github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= 49 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 50 | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 51 | github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 52 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 53 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 54 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 55 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 56 | github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= 57 | github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 58 | github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= 59 | github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= 60 | github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= 61 | github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= 62 | github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= 63 | github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= 64 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 65 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 66 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 67 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 68 | github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= 69 | github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= 70 | github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= 71 | github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= 72 | github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d h1:hrujxIzL1woJ7AwssoOcM/tq5JjjG2yYOc8odClEiXA= 73 | github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU= 74 | github.com/schollz/progressbar/v3 v3.17.1 h1:bI1MTaoQO+v5kzklBjYNRQLoVpe0zbyRZNK6DFkVC5U= 75 | github.com/schollz/progressbar/v3 v3.17.1/go.mod h1:RzqpnsPQNjUyIgdglUjRLgD7sVnxN1wpmBMV+UiEbL4= 76 | github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= 77 | github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= 78 | github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= 79 | github.com/skeema/knownhosts v1.3.0 h1:AM+y0rI04VksttfwjkSTNQorvGqmwATnvnAHpSgc0LY= 80 | github.com/skeema/knownhosts v1.3.0/go.mod h1:sPINvnADmT/qYH1kfv+ePMmOBTH6Tbl7b5LvTDjFK7M= 81 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 82 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 83 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 84 | github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= 85 | github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 86 | github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= 87 | github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= 88 | golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= 89 | golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= 90 | golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= 91 | golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= 92 | golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= 93 | golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= 94 | golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= 95 | golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 96 | golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= 97 | golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= 98 | golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= 99 | golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= 100 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 101 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 102 | golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 103 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 104 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 105 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 106 | golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= 107 | golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 108 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 109 | golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= 110 | golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= 111 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 112 | golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= 113 | golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= 114 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 115 | golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= 116 | golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= 117 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 118 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 119 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 120 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 121 | gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= 122 | gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= 123 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 124 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 125 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 126 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 127 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The GNU General Public License is a free, copyleft license for software and other kinds of works. 2 | 3 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program–to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. 4 | 5 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. 6 | 7 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. 8 | 9 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 10 | 11 | Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. 12 | 13 | For the developers’ and authors’ protection, the GPL clearly explains that there is no warranty for this free software. For both users’ and authors’ sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. 14 | 15 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users’ freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. 16 | 17 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. 18 | 19 | The precise terms and conditions for copying, distribution and modification follow. 20 | 21 | TERMS AND CONDITIONS 22 | 0. Definitions. 23 | 24 | “This License” refers to version 3 of the GNU General Public License. 25 | 26 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. 27 | 28 | “The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. 29 | 30 | To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. 31 | 32 | A “covered work” means either the unmodified Program or a work based on the Program. 33 | 34 | To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. 35 | 36 | To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. 37 | 38 | An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 39 | 40 | 1. Source Code. 41 | 42 | The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. 43 | 44 | A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. 45 | 46 | The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. 47 | 48 | The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work’s System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. 49 | 50 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. 51 | 52 | The Corresponding Source for a work in source code form is that same work. 53 | 54 | 2. Basic Permissions. 55 | 56 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. 57 | 58 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. 59 | 60 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 61 | 62 | 3. Protecting Users’ Legal Rights From Anti-Circumvention Law. 63 | 64 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. 65 | 66 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work’s users, your or third parties’ legal rights to forbid circumvention of technological measures. 67 | 68 | 4. Conveying Verbatim Copies. 69 | 70 | You may convey verbatim copies of the Program’s source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. 71 | 72 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 73 | 74 | 5. Conveying Modified Source Versions. 75 | 76 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: 77 | 78 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date. 79 | b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. 80 | c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. 81 | d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. 82 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation’s users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 83 | 84 | 6. Conveying Non-Source Forms. 85 | 86 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: 87 | 88 | a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. 89 | b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. 90 | c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. 91 | d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. 92 | e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. 93 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. 94 | 95 | A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. 96 | 97 | “Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. 98 | 99 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). 100 | 101 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. 102 | 103 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 104 | 105 | 7. Additional Terms. 106 | 107 | “Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. 108 | 109 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. 110 | 111 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: 112 | 113 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or 114 | b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or 115 | c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or 116 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or 117 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or 118 | f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. 119 | All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. 120 | 121 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. 122 | 123 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 124 | 125 | 8. Termination. 126 | 127 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). 128 | 129 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. 130 | 131 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. 132 | 133 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 134 | 135 | 9. Acceptance Not Required for Having Copies. 136 | 137 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 138 | 139 | 10. Automatic Licensing of Downstream Recipients. 140 | 141 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. 142 | 143 | An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party’s predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. 144 | 145 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 146 | 147 | 11. Patents. 148 | 149 | A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor’s “contributor version”. 150 | 151 | A contributor’s “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. 152 | 153 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor’s essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. 154 | 155 | In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. 156 | 157 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient’s use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. 158 | 159 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. 160 | 161 | A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. 162 | 163 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 164 | 165 | 12. No Surrender of Others’ Freedom. 166 | 167 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 168 | 169 | 13. Use with the GNU Affero General Public License. 170 | 171 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 172 | 173 | 14. Revised Versions of this License. 174 | 175 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 176 | 177 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. 178 | 179 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy’s public statement of acceptance of a version permanently authorizes you to choose that version for the Program. 180 | 181 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 182 | 183 | 15. Disclaimer of Warranty. 184 | 185 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 186 | 187 | 16. Limitation of Liability. 188 | 189 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 190 | 191 | 17. Interpretation of Sections 15 and 16. 192 | 193 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. 194 | 195 | END OF TERMS AND CONDITIONS 196 | 197 | How to Apply These Terms to Your New Programs 198 | 199 | If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. 200 | 201 | To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. 202 | 203 | Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . 204 | 205 | Also add information on how to contact you by electronic and paper mail. 206 | 207 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: 208 | 209 | Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w’. This is free software, and you are welcome to redistribute it under certain conditions; type `show c’ for details. 210 | 211 | The hypothetical commands `show w’ and `show c’ should show the appropriate parts of the General Public License. Of course, your program’s commands might be different; for a GUI interface, you would use an “about box”. 212 | 213 | You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . 214 | 215 | The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . 216 | 217 | --------------------------------------------------------------------------------