Skip to content

Commit 902bedf

Browse files
committed
feat: wire watch
1 parent 1a7953b commit 902bedf

7 files changed

Lines changed: 464 additions & 2 deletions

File tree

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,26 @@ wire
142142
Wire produces `wire_gen.go` containing explicit initialization code with no
143143
runtime dependency on Wire.
144144

145+
## Running generation manually
146+
147+
Run the default command (alias for `wire gen`) or specify packages:
148+
149+
```sh
150+
wire
151+
wire gen ./...
152+
```
153+
154+
## Watching for changes
155+
156+
Wire includes a native watcher that re-runs generation on Go file changes:
157+
158+
```sh
159+
wire watch
160+
wire watch ./...
161+
```
162+
163+
Detects the package root automatically and uses native filesystem notifications when available (with a polling fallback).
164+
145165
## Design Guidance
146166

147167
Wire favors explicitness and long-term maintainability:
@@ -188,4 +208,3 @@ For questions and discussion, use
188208
189209
This project follows the Go
190210
[Code of Conduct](./CODE_OF_CONDUCT.md).
191-

cmd/wire/gen_cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (cmd *genCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interfa
108108
continue
109109
}
110110
if err := out.Commit(); err == nil {
111-
log.Printf("%s: wrote %s\n", out.PkgPath, out.OutputPath)
111+
log.Printf("%s: wrote %s (%s)\n", out.PkgPath, out.OutputPath, formatDuration(time.Since(totalStart)))
112112
} else {
113113
log.Printf("%s: failed to write %s: %v\n", out.PkgPath, out.OutputPath, err)
114114
success = false

cmd/wire/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func main() {
4343
subcommands.Register(&cacheCmd{}, "")
4444
subcommands.Register(&diffCmd{}, "")
4545
subcommands.Register(&genCmd{}, "")
46+
subcommands.Register(&watchCmd{}, "")
4647
subcommands.Register(&showCmd{}, "")
4748
flag.Parse()
4849

@@ -65,6 +66,7 @@ func main() {
6566
"gen": true,
6667
"serve": true,
6768
"show": true,
69+
"watch": true,
6870
}
6971
// Default to running the "gen" command.
7072
if args := flag.Args(); len(args) == 0 || !allCmds[args[0]] {

0 commit comments

Comments
 (0)