-
Notifications
You must be signed in to change notification settings - Fork 1
/
serve.go
38 lines (33 loc) · 841 Bytes
/
serve.go
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
package cmd
import (
"errors"
"fmt"
"strconv"
"github.com/bakito/cert-fetcher/cert/server"
"github.com/spf13/cobra"
)
// serveCmd represents the serve command
var serveCmd = &cobra.Command{
Version: version,
Use: "serve [port]",
Short: "serve on tls port and print presented client certificates",
Long: "serve on tls port and print presented client certificates",
Args: func(_ *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("port argument must be provided")
}
_, err := strconv.Atoi(args[0])
if err != nil {
return fmt.Errorf("port is invalid: %w", err)
}
return err
},
ValidArgs: []string{"port"},
RunE: func(_ *cobra.Command, args []string) error {
port, _ := strconv.Atoi(args[0])
return server.Serve(port)
},
}
func init() {
rootCmd.AddCommand(serveCmd)
}