Skip to content

Commit 79d7981

Browse files
remove unwanted commands
1 parent 32867bb commit 79d7981

File tree

1 file changed

+4
-178
lines changed

1 file changed

+4
-178
lines changed

main.go

Lines changed: 4 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"github.com/cloudimpl/polycode/core"
1010
_go "github.com/cloudimpl/polycode/go"
11-
"github.com/fsnotify/fsnotify"
1211
"io"
1312
"log"
1413
"net/http"
@@ -55,9 +54,6 @@ func main() {
5554
case "build":
5655
cmdBuild(os.Args[2:])
5756

58-
case "run":
59-
cmdRun(os.Args[2:])
60-
6157
case "extract":
6258
cmdExtract(os.Args[2:])
6359

@@ -181,12 +177,10 @@ func cmdBuild(args []string) {
181177
var (
182178
appLanguage string
183179
outputPath string
184-
watchFlag bool
185180
)
186181

187182
fs.StringVar(&appLanguage, "language", "auto", "Application language (supported: go)")
188183
fs.StringVar(&outputPath, "out", "", "Output path for generated code (default: <app-path>/app)")
189-
fs.BoolVar(&watchFlag, "watch", false, "Watch <app-path>/services and rebuild on changes")
190184
fs.Usage = func() {
191185
fmt.Fprintf(fs.Output(), "Usage:\n polycode build <app-path> [options]\n\nOptions:\n")
192186
fs.PrintDefaults()
@@ -230,107 +224,11 @@ func cmdBuild(args []string) {
230224
log.Fatalf("language %q is not supported", appLanguage)
231225
}
232226

233-
if watchFlag {
234-
servicesPath := filepath.Join(appPath, "services")
235-
log.Printf("watching: %s", servicesPath)
236-
watch(servicesPath, func(event fsnotify.Event) {
237-
_ = g.OnChange(appPath, outputPath, event)
238-
})
239-
return
240-
}
241-
242227
if err := g.Generate(appPath, outputPath); err != nil {
243228
log.Fatalf("failed to build: %v", err)
244229
}
245230
}
246231

247-
// ========================= run =========================
248-
249-
// polycode run <app-path>
250-
// - Builds into <app-path>/app (like build)
251-
// - For Go: builds binary into .polycode/app and runs it
252-
func cmdRun(args []string) {
253-
fs := flag.NewFlagSet("run", flag.ContinueOnError)
254-
fs.SetOutput(os.Stderr)
255-
256-
var (
257-
appLanguage string
258-
)
259-
fs.StringVar(&appLanguage, "language", "auto", "Application language (supported: go)")
260-
fs.Usage = func() {
261-
fmt.Fprintf(fs.Output(), "Usage:\n polycode run <app-path> [options]\n\nOptions:\n")
262-
fs.PrintDefaults()
263-
}
264-
265-
if err := fs.Parse(args); err != nil {
266-
if err == flag.ErrHelp {
267-
return
268-
}
269-
os.Exit(2)
270-
}
271-
if fs.NArg() < 1 {
272-
fmt.Fprintln(os.Stderr, "missing required <app-path>")
273-
fs.Usage()
274-
os.Exit(2)
275-
}
276-
appPath := fs.Arg(0)
277-
278-
// detect language
279-
if appLanguage == "" || appLanguage == "auto" {
280-
appLanguage = detectLanguage(appPath)
281-
if appLanguage == "" {
282-
log.Fatalf("unable to detect language for %s — please specify with -language", appPath)
283-
}
284-
fmt.Println("Detected language:", appLanguage)
285-
}
286-
287-
// 1) build
288-
if err := os.MkdirAll(filepath.Join(appPath, "app"), 0o755); err != nil {
289-
log.Fatalf("failed to create app folder: %v", err)
290-
}
291-
cmdBuild([]string{appPath, "-language", appLanguage})
292-
293-
// 2) build & run (language-specific)
294-
switch appLanguage {
295-
case "go":
296-
binDir := filepath.Join(appPath, ".polycode")
297-
_ = os.MkdirAll(binDir, 0o755)
298-
bin := filepath.Join(binDir, "app")
299-
// go mod tidy at root (in case builder added deps)
300-
_ = runCmd(appPath, "go", "mod", "tidy")
301-
// build the generated app
302-
if err := runCmd(appPath, "go", "build", "-o", bin, "./app"); err != nil {
303-
log.Fatalf("build binary failed: %v", err)
304-
}
305-
fmt.Printf("▶ Running %s\n\n", bin)
306-
// exec the app and proxy signals
307-
ctx, cancel := context.WithCancel(context.Background())
308-
defer cancel()
309-
310-
cmd := exec.CommandContext(ctx, bin)
311-
cmd.Stdout, cmd.Stderr, cmd.Stdin = os.Stdout, os.Stderr, os.Stdin
312-
if err := cmd.Start(); err != nil {
313-
log.Fatalf("failed to start: %v", err)
314-
}
315-
done := make(chan struct{})
316-
go func() {
317-
handleSignals(func() {
318-
gracefulStop(cmd.Process)
319-
})
320-
_ = cmd.Wait()
321-
close(done)
322-
}()
323-
<-done
324-
325-
case "java":
326-
log.Fatalf("run: java pipeline not implemented yet")
327-
case "python":
328-
log.Fatalf("run: python pipeline not implemented yet")
329-
default:
330-
log.Fatalf("run: unsupported language %q", appLanguage)
331-
}
332-
}
333-
334232
// ========================= extract =========================
335233

336234
func cmdExtract(args []string) {
@@ -476,70 +374,6 @@ func runExtractor(client, out, callback, cwd string) {
476374

477375
// ========================= helpers =========================
478376

479-
func watch(watchPath string, onChange func(event fsnotify.Event)) {
480-
watcher, err := fsnotify.NewWatcher()
481-
if err != nil {
482-
log.Fatalf("failed to create watcher: %v", err)
483-
}
484-
defer watcher.Close()
485-
486-
// Handle OS signals for graceful shutdown
487-
done := make(chan struct{})
488-
489-
go func() {
490-
defer close(done)
491-
for {
492-
select {
493-
case event, ok := <-watcher.Events:
494-
if !ok {
495-
return
496-
}
497-
498-
// auto-add new directories
499-
if event.Op&fsnotify.Create == fsnotify.Create {
500-
if info, err := os.Stat(event.Name); err == nil && info.IsDir() {
501-
if err := watcher.Add(event.Name); err != nil {
502-
log.Printf("failed to watch new dir %s: %v", event.Name, err)
503-
}
504-
}
505-
}
506-
507-
if event.Op&fsnotify.Write == fsnotify.Write {
508-
onChange(event)
509-
}
510-
511-
case err, ok := <-watcher.Errors:
512-
if !ok {
513-
return
514-
}
515-
log.Printf("watcher error: %v", err)
516-
}
517-
}
518-
}()
519-
520-
// initial walk
521-
err = filepath.Walk(watchPath, func(p string, info os.FileInfo, err error) error {
522-
if err != nil {
523-
log.Printf("walk error on %s: %v", p, err)
524-
return err
525-
}
526-
if info.IsDir() {
527-
return watcher.Add(p)
528-
}
529-
return nil
530-
})
531-
if err != nil {
532-
log.Fatalf("failed to initialize watcher: %v", err)
533-
}
534-
535-
// Block forever; exit on signal
536-
handleSignals(func() {
537-
watcher.Close()
538-
})
539-
540-
<-done
541-
}
542-
543377
func handleSignals(onTerm func()) {
544378
sig := make(chan os.Signal, 1)
545379
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
@@ -764,27 +598,19 @@ Usage:
764598
765599
Commands:
766600
new Create a new project from the getting-started repo
767-
build Build code from an app folder (with optional watch mode)
768-
run Build then run the app (Go supported)
769-
extract Run a client binary and capture its startup POST payload
601+
build Build code from an app folder
602+
extract Run app binary and capture its startup POST payload
770603
771604
Run 'polycode <command> -h' for more details.
772605
773606
Examples:
774607
# Create a new project
775608
polycode new myapp -language go
776-
cd myapp
777-
polycode build .
778-
go run ./app
779609
780610
# Build in-place
781-
polycode build ./myapp -language go -out ./myapp/app
782-
polycode build ./myapp -watch
783-
784-
# Run (build + binary + execute)
785-
polycode run ./myapp
611+
polycode build ./myapp
786612
787613
# Extract startup metadata from an app binary
788-
polycode extract ./bin/myclient -out ./meta.json -callback http://localhost:8080/hook -cwd ./sandbox
614+
polycode extract ./myapp/app
789615
`)
790616
}

0 commit comments

Comments
 (0)