Skip to content
File

Blob: cmd/client/serve.go

go33 lines
1package client
2 
3import (
4 "context"
5 "fmt"
6 "os"
7 
8 "github.com/urfave/cli/v3"
9)
10 
11func serveCommand() *cli.Command {
12 return &cli.Command{
13 Name: "serve",
14 Usage: "Serve a registered hostname using a domain token",
15 ArgsUsage: "<target>",
16 Flags: append(lightweightFlags(), &cli.StringFlag{
17 Name: "token-file",
18 Usage: "read the bearer token from this file (or use SPECTER_TUNNEL_TOKEN)",
19 }),
20 Action: func(ctx context.Context, cmd *cli.Command) error {
21 env, set := os.LookupEnv("SPECTER_TUNNEL_TOKEN")
22 if cmd.IsSet("token-file") && set {
23 return fmt.Errorf("specify exactly one of --token-file or SPECTER_TUNNEL_TOKEN")
24 }
25 token, err := loadTunnelToken(cmd.String("token-file"), env, set)
26 if err != nil {
27 return err
28 }
29 return runLightweight(ctx, cmd, token)
30 },
31 }
32}