@@ -28,23 +28,36 @@ type Config struct {
28
28
29
29
// NewCommand creates and returns the root serpent command
30
30
func NewCommand () * serpent.Command {
31
- var config Config
32
-
33
- return & serpent.Command {
34
- Use : "jail [flags] -- command [args...]" ,
35
- Short : "Monitor and restrict HTTP/HTTPS requests from processes" ,
36
- Long : `jail creates an isolated network environment for the target process,
37
- intercepting all HTTP/HTTPS traffic through a transparent proxy that enforces
38
- user-defined rules.
39
-
40
- Examples:
31
+ // To make the top level jail command, we just make some minor changes to the base command
32
+ cmd := BaseCommand ()
33
+ cmd .Use = "jail [flags] -- command [args...]" // Add the flags and args pieces to usage.
34
+
35
+ // Add example usage to the long description. This is different from usage as a subcommand because it
36
+ // may be called something different when used as a subcommand / there will be a leading binary (i.e. `coder jail` vs. `jail`).
37
+ cmd .Long += `Examples:
41
38
# Allow only requests to github.com
42
39
jail --allow "github.com" -- curl https://github.com
43
40
44
41
# Monitor all requests to specific domains (allow only those)
45
42
jail --allow "github.com/api/issues/*" --allow "GET,HEAD github.com" -- npm install
46
43
47
- # Block everything by default (implicit)` ,
44
+ # Block everything by default (implicit)`
45
+
46
+ return cmd
47
+ }
48
+
49
+ // Base command returns the jail serpent command without the information involved in making it the
50
+ // *top level* serpent command. We are creating this split to make it easier to integrate into the coder
51
+ // cli without introducing sources of drift.
52
+ func BaseCommand () * serpent.Command {
53
+ var config Config
54
+
55
+ return & serpent.Command {
56
+ Use : "jail -- command" ,
57
+ Short : "Monitor and restrict HTTP/HTTPS requests from processes" ,
58
+ Long : `creates an isolated network environment for the target process,
59
+ intercepting all HTTP/HTTPS traffic through a transparent proxy that enforces
60
+ user-defined rules.` ,
48
61
Options : serpent.OptionSet {
49
62
{
50
63
Name : "allow" ,
0 commit comments