-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcoverage.html
More file actions
6392 lines (5412 loc) · 264 KB
/
Copy pathcoverage.html
File metadata and controls
6392 lines (5412 loc) · 264 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>cmd: Go Coverage Report</title>
<style>
body {
background: black;
color: rgb(80, 80, 80);
}
body, pre, #legend span {
font-family: Menlo, monospace;
font-weight: bold;
}
#topbar {
background: black;
position: fixed;
top: 0; left: 0; right: 0;
height: 42px;
border-bottom: 1px solid rgb(80, 80, 80);
}
#content {
margin-top: 50px;
}
#nav, #legend {
float: left;
margin-left: 10px;
}
#legend {
margin-top: 12px;
}
#nav {
margin-top: 10px;
}
#legend span {
margin: 0 5px;
}
.cov0 { color: rgb(192, 0, 0) }
.cov1 { color: rgb(128, 128, 128) }
.cov2 { color: rgb(116, 140, 131) }
.cov3 { color: rgb(104, 152, 134) }
.cov4 { color: rgb(92, 164, 137) }
.cov5 { color: rgb(80, 176, 140) }
.cov6 { color: rgb(68, 188, 143) }
.cov7 { color: rgb(56, 200, 146) }
.cov8 { color: rgb(44, 212, 149) }
.cov9 { color: rgb(32, 224, 152) }
.cov10 { color: rgb(20, 236, 155) }
</style>
</head>
<body>
<div id="topbar">
<div id="nav">
<select id="files">
<option value="file0">github.com/craigderington/prox/cmd/daemon.go (0.0%)</option>
<option value="file1">github.com/craigderington/prox/cmd/delete.go (0.0%)</option>
<option value="file2">github.com/craigderington/prox/cmd/helpers.go (0.0%)</option>
<option value="file3">github.com/craigderington/prox/cmd/init.go (0.0%)</option>
<option value="file4">github.com/craigderington/prox/cmd/list.go (0.0%)</option>
<option value="file5">github.com/craigderington/prox/cmd/logs.go (0.0%)</option>
<option value="file6">github.com/craigderington/prox/cmd/output.go (0.0%)</option>
<option value="file7">github.com/craigderington/prox/cmd/restart.go (0.0%)</option>
<option value="file8">github.com/craigderington/prox/cmd/root.go (0.0%)</option>
<option value="file9">github.com/craigderington/prox/cmd/start.go (0.0%)</option>
<option value="file10">github.com/craigderington/prox/cmd/startall.go (0.0%)</option>
<option value="file11">github.com/craigderington/prox/cmd/stop.go (0.0%)</option>
<option value="file12">github.com/craigderington/prox/internal/banner/banner.go (0.0%)</option>
<option value="file13">github.com/craigderington/prox/internal/config/autodiscover.go (0.0%)</option>
<option value="file14">github.com/craigderington/prox/internal/config/config.go (92.7%)</option>
<option value="file15">github.com/craigderington/prox/internal/daemon/client.go (0.0%)</option>
<option value="file16">github.com/craigderington/prox/internal/daemon/server.go (0.0%)</option>
<option value="file17">github.com/craigderington/prox/internal/logs/logger.go (0.0%)</option>
<option value="file18">github.com/craigderington/prox/internal/logs/merger.go (0.0%)</option>
<option value="file19">github.com/craigderington/prox/internal/manager/shared.go (0.0%)</option>
<option value="file20">github.com/craigderington/prox/internal/process/manager.go (61.4%)</option>
<option value="file21">github.com/craigderington/prox/internal/process/metrics.go (0.0%)</option>
<option value="file22">github.com/craigderington/prox/internal/process/persistence.go (0.0%)</option>
<option value="file23">github.com/craigderington/prox/internal/process/types.go (0.0%)</option>
<option value="file24">github.com/craigderington/prox/internal/storage/storage.go (57.6%)</option>
<option value="file25">github.com/craigderington/prox/internal/tui/app.go (0.0%)</option>
<option value="file26">github.com/craigderington/prox/internal/tui/dashboard.go (0.0%)</option>
<option value="file27">github.com/craigderington/prox/internal/tui/logs.go (0.0%)</option>
<option value="file28">github.com/craigderington/prox/internal/tui/monitor.go (0.0%)</option>
<option value="file29">github.com/craigderington/prox/internal/tui/styles.go (0.0%)</option>
<option value="file30">github.com/craigderington/prox/main.go (0.0%)</option>
</select>
</div>
<div id="legend">
<span>not tracked</span>
<span class="cov0">not covered</span>
<span class="cov8">covered</span>
</div>
</div>
<div id="content">
<pre class="file" id="file0" style="display: none">package cmd
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"time"
"github.com/craigderington/prox/internal/daemon"
"github.com/craigderington/prox/internal/process"
"github.com/spf13/cobra"
)
var daemonCmd = &cobra.Command{
Use: "daemon",
Short: "Manage the prox daemon",
Long: `Start, stop, or check status of the background prox daemon for auto-restart`,
}
var daemonStartCmd = &cobra.Command{
Use: "start",
Short: "Start the prox daemon",
Run: func(cmd *cobra.Command, args []string) <span class="cov0" title="0">{
// Check if already running
client, err := daemon.NewClient()
if err != nil </span><span class="cov0" title="0">{
PrintError("Failed to create client: %v", err)
os.Exit(1)
}</span>
<span class="cov0" title="0">if client.IsRunning() </span><span class="cov0" title="0">{
PrintWarning("Daemon already running")
return
}</span>
// Get executable path
<span class="cov0" title="0">exePath, err := os.Executable()
if err != nil </span><span class="cov0" title="0">{
PrintError("Failed to get executable path: %v", err)
os.Exit(1)
}</span>
// Start daemon in background
<span class="cov0" title="0">daemonCmd := exec.Command(exePath, "daemon", "run")
daemonCmd.Stdout = nil
daemonCmd.Stderr = nil
daemonCmd.Stdin = nil
if err := daemonCmd.Start(); err != nil </span><span class="cov0" title="0">{
PrintError("Failed to start daemon: %v", err)
os.Exit(1)
}</span>
// Detach from parent
<span class="cov0" title="0">daemonCmd.Process.Release()
// Wait for daemon to be ready
PrintInfo("Starting daemon...")
for i := 0; i < 10; i++ </span><span class="cov0" title="0">{
time.Sleep(200 * time.Millisecond)
if client.IsRunning() </span><span class="cov0" title="0">{
PrintSuccess("✓ Daemon started")
PrintMuted(" • Auto-restart is now enabled")
PrintMuted(" • Processes will restart on crash")
PrintMuted(" • Use 'prox daemon stop' to stop the daemon")
return
}</span>
}
<span class="cov0" title="0">PrintWarning("Daemon started but not responding")</span>
},
}
var daemonStopCmd = &cobra.Command{
Use: "stop",
Short: "Stop the prox daemon",
Run: func(cmd *cobra.Command, args []string) <span class="cov0" title="0">{
client, err := daemon.NewClient()
if err != nil </span><span class="cov0" title="0">{
PrintError("Failed to create client: %v", err)
os.Exit(1)
}</span>
<span class="cov0" title="0">if !client.IsRunning() </span><span class="cov0" title="0">{
PrintMuted("Daemon not running")
return
}</span>
<span class="cov0" title="0">PrintInfo("Stopping daemon...")
if err := client.Shutdown(); err != nil </span><span class="cov0" title="0">{
PrintError("Failed to stop daemon: %v", err)
os.Exit(1)
}</span>
<span class="cov0" title="0">PrintSuccess("✓ Daemon stopped")
PrintMuted(" • Auto-restart is now disabled")
PrintMuted(" • Running processes will continue")</span>
},
}
var daemonStatusCmd = &cobra.Command{
Use: "status",
Short: "Check daemon status",
Run: func(cmd *cobra.Command, args []string) <span class="cov0" title="0">{
client, err := daemon.NewClient()
if err != nil </span><span class="cov0" title="0">{
PrintError("Failed to create client: %v", err)
os.Exit(1)
}</span>
<span class="cov0" title="0">if client.IsRunning() </span><span class="cov0" title="0">{
PrintSuccess("✓ Daemon is running")
// Get process list
processes, err := client.List()
if err != nil </span><span class="cov0" title="0">{
PrintWarning(" Failed to get process list: %v", err)
return
}</span>
<span class="cov0" title="0">online := 0
for _, p := range processes </span><span class="cov0" title="0">{
if p.Status == process.StatusOnline </span><span class="cov0" title="0">{
online++
}</span>
}
<span class="cov0" title="0">PrintMuted(" • Managing %d process(es)", len(processes))
PrintMuted(" • %d online", online)
// Show socket path
configDir, _ := process.ConfigDir()
sockPath := filepath.Join(configDir, "daemon.sock")
PrintMuted(" • Socket: %s", sockPath)</span>
} else<span class="cov0" title="0"> {
PrintMuted("✗ Daemon is not running")
PrintMuted(" • Start with: prox daemon start")
PrintMuted(" • Auto-restart is disabled")
}</span>
},
}
var daemonRunCmd = &cobra.Command{
Use: "run",
Short: "Run the daemon (internal use)",
Hidden: true,
Run: func(cmd *cobra.Command, args []string) <span class="cov0" title="0">{
server, err := daemon.NewServer()
if err != nil </span><span class="cov0" title="0">{
fmt.Fprintf(os.Stderr, "Failed to create server: %v\n", err)
os.Exit(1)
}</span>
// Redirect output to log file
<span class="cov0" title="0">configDir, _ := process.ConfigDir()
logPath := filepath.Join(configDir, "daemon.log")
logFile, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err == nil </span><span class="cov0" title="0">{
os.Stdout = logFile
os.Stderr = logFile
defer logFile.Close()
}</span>
<span class="cov0" title="0">if err := server.Start(); err != nil </span><span class="cov0" title="0">{
fmt.Fprintf(os.Stderr, "Daemon error: %v\n", err)
os.Exit(1)
}</span>
},
}
func init() <span class="cov0" title="0">{
rootCmd.AddCommand(daemonCmd)
daemonCmd.AddCommand(daemonStartCmd)
daemonCmd.AddCommand(daemonStopCmd)
daemonCmd.AddCommand(daemonStatusCmd)
daemonCmd.AddCommand(daemonRunCmd)
}</span>
</pre>
<pre class="file" id="file1" style="display: none">package cmd
import (
"os"
"github.com/spf13/cobra"
)
var deleteCmd = &cobra.Command{
Use: "delete <name|id>",
Aliases: []string{"del", "rm"},
Short: "Delete a process",
Long: `Delete a process (stops it first if running)`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) <span class="cov0" title="0">{
nameOrID := args[0]
// Get shared manager
mgr, _, err := getManager()
if err != nil </span><span class="cov0" title="0">{
PrintError("Failed to initialize manager: %v", err)
os.Exit(1)
}</span>
// Delete process
<span class="cov0" title="0">if err := mgr.Delete(nameOrID); err != nil </span><span class="cov0" title="0">{
PrintError("Failed to delete process: %v", err)
os.Exit(1)
}</span>
// Save state
<span class="cov0" title="0">if err := saveState(); err != nil </span><span class="cov0" title="0">{
PrintWarning("Failed to save state: %v", err)
}</span>
<span class="cov0" title="0">PrintSuccess("Deleted '%s'", nameOrID)</span>
},
}
func init() <span class="cov0" title="0">{
rootCmd.AddCommand(deleteCmd)
}</span>
</pre>
<pre class="file" id="file2" style="display: none">package cmd
import (
"github.com/craigderington/prox/internal/manager"
"github.com/craigderington/prox/internal/process"
"github.com/craigderington/prox/internal/storage"
)
// getManager returns the shared process manager and storage
func getManager() (*process.Manager, *storage.Storage, error) <span class="cov0" title="0">{
return manager.Get()
}</span>
// saveState saves the current manager state
func saveState() error <span class="cov0" title="0">{
return manager.Save()
}</span>
</pre>
<pre class="file" id="file3" style="display: none">package cmd
import (
"fmt"
"os"
"github.com/charmbracelet/lipgloss"
"github.com/craigderington/prox/internal/config"
"github.com/spf13/cobra"
)
var (
initFile string
)
var initCmd = &cobra.Command{
Use: "init",
Short: "Initialize prox configuration from existing project files",
Long: `Auto-discover services from Procfile, package.json, or docker-compose.yml
and create a prox.yml configuration file.
Examples:
prox init # Auto-discover from current directory
prox init -f ../Procfile # Use specific Procfile
prox init -f config/prod.Procfile`,
Run: func(cmd *cobra.Command, args []string) <span class="cov0" title="0">{
// Check if prox.yml already exists
if _, err := os.Stat("prox.yml"); err == nil </span><span class="cov0" title="0">{
PrintError("prox.yml already exists. Delete it first or edit manually.")
os.Exit(1)
}</span>
// Auto-discover services
<span class="cov0" title="0">PrintInfo("🔍 Discovering services...")
var cfg *config.Config
var err error
var source string
if initFile != "" </span><span class="cov0" title="0">{
// Use specific file
source = initFile
PrintInfo("Using file: %s", initFile)
cfg, err = config.AutoDiscoverFromFile(initFile)
}</span> else<span class="cov0" title="0"> {
// Auto-discover
cfg, err = config.AutoDiscover()
source = config.GetDiscoverySource()
}</span>
<span class="cov0" title="0">if err != nil </span><span class="cov0" title="0">{
PrintError("Failed to discover services: %v", err)
if initFile == "" </span><span class="cov0" title="0">{
PrintMuted("\nSupported files:")
PrintMuted(" • Procfile")
PrintMuted(" • package.json (npm scripts)")
PrintMuted(" • docker-compose.yml")
PrintMuted("\nOr use -f to specify a file")
}</span>
<span class="cov0" title="0">os.Exit(1)</span>
}
<span class="cov0" title="0">PrintSuccess("✓ Found %d service(s) in %s", len(cfg.Services), source)
// Show discovered services
fmt.Println()
PrintInfo("Discovered services:")
for name, svc := range cfg.Services </span><span class="cov0" title="0">{
nameStyle := lipgloss.NewStyle().Foreground(colorSuccess).Render(name)
cmdStyle := lipgloss.NewStyle().Foreground(colorMuted).Render(svc.Command)
fmt.Printf(" • %s: %s\n", nameStyle, cmdStyle)
}</span>
// Save to prox.yml
<span class="cov0" title="0">fmt.Println()
PrintInfo("📝 Writing prox.yml...")
if err := config.SaveConfig("prox.yml", cfg); err != nil </span><span class="cov0" title="0">{
PrintError("Failed to save config: %v", err)
os.Exit(1)
}</span>
<span class="cov0" title="0">PrintSuccess("✓ Created prox.yml")
fmt.Println()
PrintMuted("Next steps:")
PrintMuted(" 1. Review and edit prox.yml if needed")
PrintMuted(" 2. Run 'prox start' to start all services")
PrintMuted(" 3. Run 'prox' to open the TUI dashboard")</span>
},
}
func init() <span class="cov0" title="0">{
rootCmd.AddCommand(initCmd)
initCmd.Flags().StringVarP(&initFile, "file", "f", "", "Specific config file to use (Procfile, package.json, docker-compose.yml)")
}</span>
</pre>
<pre class="file" id="file4" style="display: none">package cmd
import (
"fmt"
"os"
"strings"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
"github.com/craigderington/prox/internal/banner"
"github.com/craigderington/prox/internal/process"
"github.com/spf13/cobra"
)
var (
showBanner bool
)
var listCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls", "status"},
Short: "List all processes",
Long: `Display a list of all managed processes with their status`,
Run: func(cmd *cobra.Command, args []string) <span class="cov0" title="0">{
// Get shared manager
mgr, _, err := getManager()
if err != nil </span><span class="cov0" title="0">{
PrintError("Failed to initialize manager: %v", err)
os.Exit(1)
}</span>
<span class="cov0" title="0">processes := mgr.List()
// Show banner if requested or if no processes
if showBanner || len(processes) == 0 </span><span class="cov0" title="0">{
fmt.Println(banner.Render())
}</span>
<span class="cov0" title="0">if len(processes) == 0 </span><span class="cov0" title="0">{
PrintMuted("No processes running. Get started:")
PrintMuted(" $ prox init # Auto-discover services")
PrintMuted(" $ prox start app.js # Start a single process")
return
}</span>
// Print compact header if banner not shown
<span class="cov0" title="0">if !showBanner </span><span class="cov0" title="0">{
headerStyle := lipgloss.NewStyle().Foreground(colorInfo).Bold(true)
fmt.Println(headerStyle.Render("⚡ prox - Process List"))
fmt.Println()
}</span>
// Collect metrics for all processes
<span class="cov0" title="0">collector := process.NewMetricsCollector(mgr)
metricsMap := collector.CollectAllMetrics()
// Build table rows
rows := [][]string{}
for i, proc := range processes </span><span class="cov0" title="0">{
metrics := metricsMap[proc.ID]
uptime := "-"
if proc.Status == process.StatusOnline </span><span class="cov0" title="0">{
uptime = process.FormatDuration(proc.Uptime())
}</span>
// CPU and Memory
<span class="cov0" title="0">cpu := "-"
mem := "-"
if metrics != nil && proc.Status == process.StatusOnline </span><span class="cov0" title="0">{
cpu = fmt.Sprintf("%.1f%%", metrics.CPU)
mem = process.FormatBytes(metrics.Memory)
}</span>
// Status with symbol
<span class="cov0" title="0">statusStr := string(proc.Status)
var statusWithSymbol string
switch proc.Status </span>{
case process.StatusOnline:<span class="cov0" title="0">
statusWithSymbol = "● " + statusStr</span>
case process.StatusStopped:<span class="cov0" title="0">
statusWithSymbol = "○ " + statusStr</span>
case process.StatusErrored:<span class="cov0" title="0">
statusWithSymbol = "✗ " + statusStr</span>
case process.StatusRestarting:<span class="cov0" title="0">
statusWithSymbol = "↻ " + statusStr</span>
default:<span class="cov0" title="0">
statusWithSymbol = statusStr</span>
}
<span class="cov0" title="0">rows = append(rows, []string{
fmt.Sprintf("%d", i),
proc.Name,
statusWithSymbol,
fmt.Sprintf("%d", proc.Restarts),
cpu,
mem,
uptime,
proc.Script,
})</span>
}
// Create beautiful lipgloss table
<span class="cov0" title="0">colorBorder := lipgloss.Color("#45475A")
tableHeaderStyle := lipgloss.NewStyle().
Foreground(colorInfo).
Bold(true).
Align(lipgloss.Left)
t := table.New().
Border(lipgloss.RoundedBorder()).
BorderStyle(lipgloss.NewStyle().Foreground(colorBorder)).
StyleFunc(func(row, col int) lipgloss.Style </span><span class="cov0" title="0">{
// Header row
if row == 0 </span><span class="cov0" title="0">{
return tableHeaderStyle
}</span>
// Bounds check for data rows
<span class="cov0" title="0">dataRow := row - 1
if dataRow < 0 || dataRow >= len(rows) </span><span class="cov0" title="0">{
return mutedStyle
}</span>
// Status column (col 2) - apply color coding
<span class="cov0" title="0">if col == 2 </span><span class="cov0" title="0">{
// Get the status text from the row
statusText := rows[dataRow][col]
// Check what status it contains
if strings.HasPrefix(statusText, "●") </span><span class="cov0" title="0">{ // online
return successStyle
}</span> else<span class="cov0" title="0"> if strings.HasPrefix(statusText, "○") </span><span class="cov0" title="0">{ // stopped
return warningStyle // Orange for stopped
}</span> else<span class="cov0" title="0"> if strings.HasPrefix(statusText, "✗") </span><span class="cov0" title="0">{ // errored
return errorStyle
}</span> else<span class="cov0" title="0"> if strings.HasPrefix(statusText, "↻") </span><span class="cov0" title="0">{ // restarting
return warningStyle
}</span>
<span class="cov0" title="0">return mutedStyle</span>
}
// CPU column - color by usage
<span class="cov0" title="0">if col == 4 </span><span class="cov0" title="0">{
return lipgloss.NewStyle().Foreground(colorInfo)
}</span>
// Memory column - color by usage
<span class="cov0" title="0">if col == 5 </span><span class="cov0" title="0">{
return lipgloss.NewStyle().Foreground(colorWarning)
}</span>
// Uptime column - muted
<span class="cov0" title="0">if col == 6 </span><span class="cov0" title="0">{
return mutedStyle
}</span>
// Script column - muted
<span class="cov0" title="0">if col == 7 </span><span class="cov0" title="0">{
return mutedStyle
}</span>
// Default
<span class="cov0" title="0">return mutedStyle</span>
}).
Headers("ID", "NAME", "STATUS", "↺", "CPU", "MEMORY", "UPTIME", "SCRIPT").
Rows(rows...)
// Add some padding around the table
<span class="cov0" title="0">tableOutput := t.Render()
paddedOutput := lipgloss.NewStyle().
Padding(0, 1).
Render(tableOutput)
fmt.Println(paddedOutput)</span>
},
}
func init() <span class="cov0" title="0">{
rootCmd.AddCommand(listCmd)
listCmd.Flags().BoolVarP(&showBanner, "banner", "b", false, "Show prox banner and info")
}</span>
</pre>
<pre class="file" id="file5" style="display: none">package cmd
import (
"fmt"
"os"
"strings"
"github.com/craigderington/prox/internal/logs"
"github.com/spf13/cobra"
)
var (
logsLines int
logsStream string
)
var logsCmd = &cobra.Command{
Use: "logs <name|id>",
Short: "View process logs",
Long: `View stdout and stderr logs for a process`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) <span class="cov0" title="0">{
nameOrID := args[0]
// Get shared manager
mgr, storage, err := getManager()
if err != nil </span><span class="cov0" title="0">{
fmt.Fprintf(os.Stderr, "⚠️ Failed to initialize manager: %v\n", err)
os.Exit(1)
}</span>
// Find process
<span class="cov0" title="0">proc := mgr.Get(nameOrID)
if proc == nil </span><span class="cov0" title="0">{
fmt.Fprintf(os.Stderr, "⚠️ Process not found: %s\n", nameOrID)
os.Exit(1)
}</span>
// Determine which log file(s) to read
<span class="cov0" title="0">var logFiles []string
var labels []string
switch strings.ToLower(logsStream) </span>{
case "out", "stdout":<span class="cov0" title="0">
logFiles = []string{storage.GetLogFile(proc.Name, "out")}
labels = []string{"STDOUT"}</span>
case "err", "stderr":<span class="cov0" title="0">
logFiles = []string{storage.GetLogFile(proc.Name, "err")}
labels = []string{"STDERR"}</span>
default:<span class="cov0" title="0"> // both
logFiles = []string{
storage.GetLogFile(proc.Name, "out"),
storage.GetLogFile(proc.Name, "err"),
}
labels = []string{"STDOUT", "STDERR"}</span>
}
// Read and display logs
<span class="cov0" title="0">fmt.Printf("📋 Logs for '%s' (last %d lines)\n\n", proc.Name, logsLines)
for i, logFile := range logFiles </span><span class="cov0" title="0">{
lines, err := logs.ReadTail(logFile, logsLines)
if err != nil </span><span class="cov0" title="0">{
fmt.Fprintf(os.Stderr, "⚠️ Failed to read %s: %v\n", labels[i], err)
continue</span>
}
<span class="cov0" title="0">if len(lines) == 0 </span><span class="cov0" title="0">{
fmt.Printf(" [%s] No logs\n", labels[i])
continue</span>
}
<span class="cov0" title="0">for _, line := range lines </span><span class="cov0" title="0">{
fmt.Printf(" [%s] %s\n", labels[i], line)
}</span>
}
},
}
func init() <span class="cov0" title="0">{
rootCmd.AddCommand(logsCmd)
logsCmd.Flags().IntVarP(&logsLines, "lines", "n", 50, "Number of lines to show")
logsCmd.Flags().StringVarP(&logsStream, "stream", "t", "both", "Stream to show (stdout, stderr, both)")
}</span>
</pre>
<pre class="file" id="file6" style="display: none">package cmd
import (
"fmt"
"github.com/charmbracelet/lipgloss"
)
var (
// CLI color palette
colorSuccess = lipgloss.Color("#00FF87") // Green
colorError = lipgloss.Color("#FF5F87") // Red
colorWarning = lipgloss.Color("#FFD700") // Yellow
colorInfo = lipgloss.Color("#00D9FF") // Cyan
colorMuted = lipgloss.Color("#6C7086") // Gray
// CLI styles
successStyle = lipgloss.NewStyle().Foreground(colorSuccess).Bold(true)
errorStyle = lipgloss.NewStyle().Foreground(colorError).Bold(true)
warningStyle = lipgloss.NewStyle().Foreground(colorWarning).Bold(true)
infoStyle = lipgloss.NewStyle().Foreground(colorInfo).Bold(true)
mutedStyle = lipgloss.NewStyle().Foreground(colorMuted)
labelStyle = lipgloss.NewStyle().Foreground(colorMuted)
valueStyle = lipgloss.NewStyle().Foreground(colorInfo)
)
// PrintSuccess prints a success message with green checkmark
func PrintSuccess(format string, args ...interface{}) <span class="cov0" title="0">{
msg := fmt.Sprintf(format, args...)
fmt.Println(successStyle.Render("✓") + " " + successStyle.Render(msg))
}</span>
// PrintError prints an error message with red X
func PrintError(format string, args ...interface{}) <span class="cov0" title="0">{
msg := fmt.Sprintf(format, args...)
fmt.Println(errorStyle.Render("✗") + " " + errorStyle.Render(msg))
}</span>
// PrintWarning prints a warning message with yellow triangle
func PrintWarning(format string, args ...interface{}) <span class="cov0" title="0">{
msg := fmt.Sprintf(format, args...)
fmt.Println(warningStyle.Render("⚠") + " " + warningStyle.Render(msg))
}</span>
// PrintInfo prints an info message with cyan bullet
func PrintInfo(format string, args ...interface{}) <span class="cov0" title="0">{
msg := fmt.Sprintf(format, args...)
fmt.Println(infoStyle.Render("●") + " " + msg)
}</span>
// PrintDetail prints a detail line with label and value
func PrintDetail(label, value string) <span class="cov0" title="0">{
fmt.Printf(" %s %s\n", labelStyle.Render(label+":"), valueStyle.Render(value))
}</span>
// PrintMuted prints muted text
func PrintMuted(format string, args ...interface{}) <span class="cov0" title="0">{
msg := fmt.Sprintf(format, args...)
fmt.Println(mutedStyle.Render(msg))
}</span>
</pre>
<pre class="file" id="file7" style="display: none">package cmd
import (
"os"
"github.com/spf13/cobra"
)
var restartCmd = &cobra.Command{
Use: "restart <name|id>",
Short: "Restart a process",
Long: `Restart a process by name or ID`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) <span class="cov0" title="0">{
nameOrID := args[0]
// Get shared manager
mgr, _, err := getManager()
if err != nil </span><span class="cov0" title="0">{
PrintError("Failed to initialize manager: %v", err)
os.Exit(1)
}</span>
// Restart process
<span class="cov0" title="0">if err := mgr.Restart(nameOrID); err != nil </span><span class="cov0" title="0">{
PrintError("Failed to restart process: %v", err)
os.Exit(1)
}</span>
// Save state
<span class="cov0" title="0">if err := saveState(); err != nil </span><span class="cov0" title="0">{
PrintWarning("Failed to save state: %v", err)
}</span>
<span class="cov0" title="0">PrintInfo("Restarted '%s'", nameOrID)</span>
},
}
func init() <span class="cov0" title="0">{
rootCmd.AddCommand(restartCmd)
}</span>
</pre>
<pre class="file" id="file8" style="display: none">package cmd
import (
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
"github.com/craigderington/prox/internal/tui"
"github.com/craigderington/prox/internal/version"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "prox",
Short: "⚡ Process manager TUI",
Version: version.Version,
Long: ` -------------
██████╗ ██████╗ ██████╗ ██╗ ██╗
██╔══██╗██╔══██╗██╔═══██╗╚██╗██╔╝
███████╔╝██████╔╝██║ ██║ ╚███╔╝
██╔═══╝ ██╔══██╗██║ ██║ ██╔██╗
██║ ██║ ██║╚██████╔╝██╔╝ ██╗
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
⚡ Process Manager ⚡
prox is a modern process manager with a beautiful TUI
for applications in any language.
Start any application:
$ prox start app.py
Launch interactive TUI (default):
$ prox
Monitor processes in detail:
$ prox monitor
View process logs:
$ prox logs my-app
To go further checkout:
https://github.com/craigderington/prox
-------------`,
Run: func(cmd *cobra.Command, args []string) <span class="cov0" title="0">{
// If no subcommand, launch TUI
if err := launchTUI(); err != nil </span><span class="cov0" title="0">{
fmt.Fprintf(os.Stderr, "Error launching TUI: %v\n", err)
os.Exit(1)
}</span>
},
}
func Execute() <span class="cov0" title="0">{
if err := rootCmd.Execute(); err != nil </span><span class="cov0" title="0">{
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}</span>
}
func init() {<span class="cov0" title="0">
// Global flags can go here
}</span>
func launchTUI() error <span class="cov0" title="0">{
// Get shared manager and storage
mgr, store, err := getManager()
if err != nil </span><span class="cov0" title="0">{
return fmt.Errorf("failed to initialize manager: %w", err)
}</span>
// Create TUI model
<span class="cov0" title="0">model := tui.NewModel(mgr, store)
// Create Bubbletea program
p := tea.NewProgram(model, tea.WithAltScreen())
// Run the program
if _, err := p.Run(); err != nil </span><span class="cov0" title="0">{
return err
}</span>
// Save state on exit
<span class="cov0" title="0">if err := saveState(); err != nil </span><span class="cov0" title="0">{
fmt.Fprintf(os.Stderr, "Warning: failed to save state: %v\n", err)
}</span>
<span class="cov0" title="0">return nil</span>
}
</pre>
<pre class="file" id="file9" style="display: none">package cmd
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
"github.com/craigderington/prox/internal/process"
"github.com/spf13/cobra"
)
var (
processName string
processArgs []string
processCwd string
interpreter string
)
var startCmd = &cobra.Command{
Use: "start [script]",
Short: "Start a process or all services from prox.yml",
Long: `Start a new process or all services from prox.yml
Examples:
prox start # Start all services from prox.yml
prox start app.js # Start app.js with auto-detected name
prox start app.js --name my-api # Start with custom name "my-api"
prox start server.py -n backend # Start with short flag
prox start app.js -i node # Specify interpreter`,
Run: func(cmd *cobra.Command, args []string) <span class="cov0" title="0">{
// If no args, try to start from prox.yml
if len(args) == 0 </span><span class="cov0" title="0">{
startAllCmd.Run(cmd, args)
return
}</span>
<span class="cov0" title="0">script := args[0]
// Use script name as process name if not provided
if processName == "" </span><span class="cov0" title="0">{
processName = filepath.Base(script)
}</span>
// Get remaining args
<span class="cov0" title="0">if len(args) > 1 </span><span class="cov0" title="0">{
processArgs = args[1:]
}</span>
// Detect interpreter if not specified
<span class="cov0" title="0">if interpreter == "" </span><span class="cov0" title="0">{
interpreter = detectInterpreter(script)
}</span>
// Get current directory if not specified
<span class="cov0" title="0">if processCwd == "" </span><span class="cov0" title="0">{
processCwd, _ = os.Getwd()
}</span>
// Create config