mirror of
https://github.com/juanfont/headscale.git
synced 2026-02-07 20:04:00 +01:00
Convert the 10 commands that were still using Run with ErrorOutput/SuccessOutput or log.Fatal/os.Exit: - backfillNodeIPsCmd: use grpcRunE-style manual connection with error returns; simplify the confirm/force logic - getPolicy, setPolicy, checkPolicy: replace ErrorOutput with fmt.Errorf returns in both the bypass-gRPC and gRPC paths - serveCmd, configTestCmd: replace log.Fatal with error returns - mockOidcCmd: replace log.Error+os.Exit with error return - versionCmd, generatePrivateKeyCmd: replace SuccessOutput with printOutput - dumpConfigCmd: return the error instead of swallowing it
41 lines
846 B
Go
41 lines
846 B
Go
package cli
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/tailscale/squibble"
|
|
)
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(serveCmd)
|
|
}
|
|
|
|
var serveCmd = &cobra.Command{
|
|
Use: "serve",
|
|
Short: "Launches the headscale server",
|
|
Args: func(cmd *cobra.Command, args []string) error {
|
|
return nil
|
|
},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
app, err := newHeadscaleServerWithConfig()
|
|
if err != nil {
|
|
if squibbleErr, ok := errors.AsType[squibble.ValidationError](err); ok {
|
|
fmt.Printf("SQLite schema failed to validate:\n")
|
|
fmt.Println(squibbleErr.Diff)
|
|
}
|
|
|
|
return fmt.Errorf("initializing: %w", err)
|
|
}
|
|
|
|
err = app.Serve()
|
|
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
|
return fmt.Errorf("headscale ran into an error and had to shut down: %w", err)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|