~ancarda/tls-redirector

ref: 5f0b9ad56965a4fa1f18e3734f574c80e6e7340f tls-redirector/cli.go -rw-r--r-- 1.3 KiB
5f0b9ad5Mark Dain Add a basic Docker healthcheck 2 months ago
                                                                                
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
package main

import (
	"fmt"
	"io"
)

const (
	exitSuccess = 0
	exitFailure = 1
)

func handleCliArgs(w io.Writer, args []string, hasSocketActivation bool) int {
	switch args[1] {
	case "--version":
		fmt.Fprintln(w, "tls redirector", version)

	case "--help":
		fmt.Fprintln(w, "Usage:", args[0], "[OPTION]")
		fmt.Fprintln(w, "A tiny service for port 80 that rewrites URLs to HTTPS.")
		fmt.Fprintln(w, "")
		if hasSocketActivation {
			fmt.Fprintln(w, "Compiled with support for systemd socket activation.")
		} else {
			fmt.Fprintln(w, "Compiled without support for systemd socket activation.")
		}
		fmt.Fprintln(w, "")
		fmt.Fprintln(w, "Options")
		fmt.Fprintln(w, "    --help     display this help and exit")
		fmt.Fprintln(w, "    --version  output version information and exit")
		fmt.Fprintln(w, "")
		fmt.Fprintln(w, "Environmental Variables")
		fmt.Fprintln(w, "    PORT               - TCP/IP port number to listen on.")
		fmt.Fprintln(w, "    ACME_CHALLENGE_DIR - Directory to serve at", acmeChallengeURLPrefix)
		fmt.Fprintln(w, "")
		fmt.Fprintln(w, "For more help, please refer to the README. Available online:")
		fmt.Fprintln(w, "    https://git.sr.ht/~ancarda/tls-redirector/tree/master/README.md")

	default:
		fmt.Fprintln(w, "unrecognized:", args[1])
		return exitFailure
	}

	return exitSuccess
}