main.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "log"
  6. "os"
  7. "os/signal"
  8. "syscall"
  9. "github.com/spf13/cobra"
  10. "github.com/cline/cli/pkg/hostbridge"
  11. )
  12. var (
  13. port int
  14. verbose bool
  15. workspaces []string
  16. )
  17. func main() {
  18. rootCmd := &cobra.Command{
  19. Use: "cline-host",
  20. Short: "Cline Host Bridge Service",
  21. Long: `A simple host bridge service that provides host operations for Cline Core.`,
  22. RunE: runServer,
  23. }
  24. rootCmd.Flags().IntVarP(&port, "port", "p", 51052, "port to listen on")
  25. rootCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "verbose logging")
  26. rootCmd.Flags().StringSliceVar(&workspaces, "workspace", nil, "workspace paths")
  27. if err := rootCmd.Execute(); err != nil {
  28. fmt.Fprintf(os.Stderr, "Error: %v\n", err)
  29. os.Exit(1)
  30. }
  31. }
  32. func runServer(cmd *cobra.Command, args []string) error {
  33. ctx := cmd.Context()
  34. // Create gRPC hostbridge service
  35. service := hostbridge.NewGrpcServer(port, verbose, workspaces)
  36. // Handle graceful shutdown
  37. ctx, cancel := context.WithCancel(ctx)
  38. defer cancel()
  39. go func() {
  40. sigChan := make(chan os.Signal, 1)
  41. signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
  42. <-sigChan
  43. if verbose {
  44. log.Println("Shutting down hostbridge server...")
  45. }
  46. cancel()
  47. }()
  48. // Start server
  49. if verbose {
  50. log.Printf("Starting Cline Host Bridge on port %d", port)
  51. }
  52. // Run the service
  53. if err := service.Start(ctx); err != nil {
  54. return fmt.Errorf("failed to run service: %w", err)
  55. }
  56. return nil
  57. }