Use CLI flags instead of environment variables for master config

Replace env var parsing with Go's flag package:
- --watch (default: ../express)
- --workers (default: 1)
- --base-port (default: 3000)
- --port (default: 8080)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-01 17:31:08 -06:00
parent e2ea472a10
commit 30463b60a5
2 changed files with 26 additions and 22 deletions

20
TODO.md
View File

@@ -1,9 +1,17 @@
- [ ] Update check script: - [ ] Update check script:
- [ ] Run `go fmt` on all .go files - [x] shellcheck on shell scripts
- [ ] Run prettier on all .ts files - [x] `go vet` on go files
- [x] `golangci-lint` on go files
- [x] Run `go fmt` on all .go files
- [ ] Eventually, run unit tests - [ ] Eventually, run unit tests
- [ ] Adapt master program so that it reads configuration from command line - [x] Reimplement fixup.sh
- [x] run shfmt on all shell scripts (and the files they `source`)
- [x] Run `go fmt` on all .go files
- [x] Run ~~prettier~~ biome on all .ts files and maybe others
- [x] Adapt master program so that it reads configuration from command line
args instead of from environment variables args instead of from environment variables
- Should have sane defaults - Should have sane defaults
- Adding new arguments should be easy and obvious - Adding new arguments should be easy and obvious
@@ -19,3 +27,9 @@
- [ ] update framework-managed pnpm - [ ] update framework-managed pnpm
- [ ] update pnpm-managed deps - [ ] update pnpm-managed deps
- [ ] rebuild golang programs - [ ] rebuild golang programs
- [ ] If the number of workers is large, then there is a long lapse between
when you change a file and when the server responds
- One solution: start and stop workers serially: stop one, restart it with new
code; repeat
- Slow start them: only start a few at first

View File

@@ -1,30 +1,20 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
"strconv"
"syscall" "syscall"
) )
func main() { func main() {
watchedDir := os.Getenv("WATCHED_DIR") watchDir := flag.String("watch", "../express", "directory to watch for changes")
workers := flag.Int("workers", 1, "number of worker processes")
basePort := flag.Int("base-port", 3000, "base port for worker processes")
listenPort := flag.Int("port", 8080, "port for the reverse proxy to listen on")
numChildProcesses := 1 flag.Parse()
if n, err := strconv.Atoi(os.Getenv("NUM_CHILD_PROCESSES")); err == nil && n > 0 {
numChildProcesses = n
}
basePort := 3000
if p, err := strconv.Atoi(os.Getenv("BASE_PORT")); err == nil && p > 0 {
basePort = p
}
listenPort := 8080
if p, err := strconv.Atoi(os.Getenv("LISTEN_PORT")); err == nil && p > 0 {
listenPort = p
}
// Create worker pool // Create worker pool
pool := NewWorkerPool() pool := NewWorkerPool()
@@ -35,12 +25,12 @@ func main() {
fileChanges := make(chan FileChange, 10) fileChanges := make(chan FileChange, 10)
go watchFiles(watchedDir, fileChanges) go watchFiles(*watchDir, fileChanges)
go runExpress(fileChanges, numChildProcesses, basePort, pool) go runExpress(fileChanges, *workers, *basePort, pool)
// Start the reverse proxy // Start the reverse proxy
listenAddr := fmt.Sprintf(":%d", listenPort) listenAddr := fmt.Sprintf(":%d", *listenPort)
go startProxy(listenAddr, pool) go startProxy(listenAddr, pool)
// Wait for interrupt signal // Wait for interrupt signal