-
Notifications
You must be signed in to change notification settings - Fork 1k
/
help.go
166 lines (126 loc) · 6.51 KB
/
help.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright 2013 Joe Walnes and the websocketd team.
// All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
)
const (
help = `
{{binary}} ({{version}})
{{binary}} is a command line tool that will allow any executable program
that accepts input on stdin and produces output on stdout to be turned into
a WebSocket server.
Usage:
Export a single executable program a WebSocket server:
{{binary}} [options] COMMAND [command args]
Or, export an entire directory of executables as WebSocket endpoints:
{{binary}} [options] --dir=SOMEDIR
Options:
--port=PORT HTTP port to listen on.
--address=ADDRESS Address to bind to (multiple options allowed)
Use square brackets to specify IPv6 address.
Default: "" (all)
--sameorigin={true,false} Restrict (HTTP 403) protocol upgrades if the
Origin header does not match to requested HTTP
Host. Default: false.
--origin=host[:port][,host[:port]...]
Restrict (HTTP 403) protocol upgrades if the
Origin header does not match to one of the host
and port combinations listed. If the port is not
specified, any port number will match.
Default: "" (allow any origin)
--ssl Listen for HTTPS socket instead of HTTP.
--sslcert=FILE All three options must be used or all of
--sslkey=FILE them should be omitted.
--redirport=PORT Open alternative port and redirect HTTP traffic
from it to canonical address (mostly useful
for HTTPS-only configurations to redirect HTTP
traffic)
--passenv VAR[,VAR...] Lists environment variables allowed to be
passed to executed scripts. Does not work for
Windows since all the variables are kept there.
--binary={true,false} Switches communication to binary, process reads
send to browser as blobs and all reads from the
browser are immediately flushed to the process.
Default: false
--reverselookup={true,false} Perform DNS reverse lookups on remote clients.
Default: false
--dir=DIR Allow all scripts in the local directory
to be accessed as WebSockets. If using this,
option, then the standard program and args
options should not be specified.
--staticdir=DIR Serve static files in this directory over HTTP.
--cgidir=DIR Serve CGI scripts in this directory over HTTP.
--maxforks=N Limit number of processes that websocketd is
able to execute with WS and CGI handlers.
When maxforks reached the server will be
rejecting requests that require executing
another process (unlimited when 0 or negative).
Default: 0
--closems=milliseconds Specifies additional time process needs to gracefully
finish before websocketd will send termination signals
to it. Default: 0 (signals sent after 100ms, 250ms,
and 500ms of waiting)
--header="..." Set custom HTTP header to each answer. For
example: --header="Server: someserver/0.0.1"
--header-ws="...." Same as --header, just applies to only those
responses that indicate upgrade of TCP connection
to a WebSockets protocol.
--header-http="...." Same as --header, just applies to only to plain
HTTP responses that do not indicate WebSockets
upgrade
--help Print help and exit.
--version Print version and exit.
--license Print license and exit.
--devconsole Enable interactive development console.
This enables you to access the websocketd
server with a web-browser and use a
user interface to quickly test WebSocket
endpoints. For example, to test an
endpoint at ws://[host]/foo, you can
visit http://[host]/foo in your browser.
This flag cannot be used in conjunction
with --staticdir or --cgidir.
--loglevel=LEVEL Log level to use (default access).
From most to least verbose:
debug, trace, access, info, error, fatal
Full documentation at http://websocketd.com/
Copyright 2013 Joe Walnes and the websocketd team. All rights reserved.
BSD license: Run '{{binary}} --license' for details.
`
short = `
Usage:
Export a single executable program a WebSocket server:
{{binary}} [options] COMMAND [command args]
Or, export an entire directory of executables as WebSocket endpoints:
{{binary}} [options] --dir=SOMEDIR
Or, show extended help message using:
{{binary}} --help
`
)
func get_help_message(content string) string {
msg := strings.Trim(content, " \n")
msg = strings.Replace(msg, "{{binary}}", HelpProcessName(), -1)
return strings.Replace(msg, "{{version}}", Version(), -1)
}
func HelpProcessName() string {
binary := os.Args[0]
if strings.Contains(binary, "/go-build") { // this was run using "go run", let's use something appropriate
binary = "websocketd"
} else {
binary = filepath.Base(binary)
}
return binary
}
func PrintHelp() {
fmt.Fprintf(os.Stderr, "%s\n", get_help_message(help))
}
func ShortHelp() {
// Shown after some error
fmt.Fprintf(os.Stderr, "\n%s\n", get_help_message(short))
}