-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
102 lines (89 loc) · 3.08 KB
/
main.go
File metadata and controls
102 lines (89 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"flag"
"fmt"
"os"
"strings"
)
var version = "dev"
const DefaultOutputFileName = "dewdrops_context.md"
type mapFlagValue struct {
enabled bool
filter string
}
func (f *mapFlagValue) String() string { return f.filter }
func (f *mapFlagValue) IsBoolFlag() bool { return true }
func (f *mapFlagValue) Set(s string) error {
f.enabled = true
if s == "true" {
f.filter = ""
} else {
f.filter = s
}
return nil
}
func main() {
var mapVal mapFlagValue
flag.Var(&mapVal, "map", "Output structural map (use --map=go,py to filter by extension, --map=any for all text files)")
fromFlag := flag.String("from", "", "Comma-separated list of file/dir paths to include")
sinceFlag := flag.String("since", "", "Git ref to diff against HEAD (branch, tag, hash, HEAD~N)")
outputFlag := flag.String("o", "", "Output file path (default: dewdrops_context.md)")
versionFlag := flag.Bool("version", false, "Print version and exit")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, `Usage: dewdrops [options] <repo-path>
Options:
--map[=exts] Output structural map (tree + signatures + token estimates).
Optionally filter by extensions (comma-separated, e.g.
--map=go,py). Default: supported languages only.
Use --map=any for all text files.
--from <paths> Only include specified files/dirs (comma-separated, relative
to repo root). Example: --from src/main.go,internal/auth/
--since <ref> Diff-aware output: map + diff + content for files changed
between <ref> and HEAD. Accepts branch names, tags, commit
hashes, or relative refs like HEAD~3.
Cannot be combined with --map or --from.
-o <path> Output file path (default: dewdrops_context.md)
--version Print version and exit
-h, --help Show this help message
Examples:
dewdrops . # Full repo dump
dewdrops --map . # Structural overview only
dewdrops --from internal/auth/ . # Dump specific directory
dewdrops --map --from internal/auth/,cmd/ . # Map of specific subtree
dewdrops --since main . # Review changes vs main
dewdrops --since HEAD~3 -o review.md . # Last 3 commits, custom path
`)
}
flag.Parse()
if *versionFlag {
fmt.Printf("dewdrops %s\n", version)
os.Exit(0)
}
if flag.NArg() < 1 {
fmt.Fprintln(os.Stderr, "Error: Missing required argument <repo-path>")
flag.Usage()
os.Exit(1)
}
rootDir := flag.Arg(0)
opts := RunOptions{
MapMode: mapVal.enabled,
MapFilter: mapVal.filter,
OutputFile: DefaultOutputFileName,
}
if *outputFlag != "" {
opts.OutputFile = *outputFlag
}
if *sinceFlag != "" {
opts.SinceRef = *sinceFlag
if *outputFlag == "" {
opts.OutputFile = sinceOutputFileName(*sinceFlag)
}
}
if *fromFlag != "" {
opts.FromPaths = strings.Split(*fromFlag, ",")
}
if err := Run(rootDir, opts); err != nil {
fmt.Fprintf(os.Stderr, "❌ %v\n", err)
os.Exit(1)
}
}