@@ -28,23 +28,36 @@ type Config struct {
2828
2929// NewCommand creates and returns the root serpent command
3030func 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:
4138 # Allow only requests to github.com
4239 jail --allow "github.com" -- curl https://github.com
4340
4441 # Monitor all requests to specific domains (allow only those)
4542 jail --allow "github.com/api/issues/*" --allow "GET,HEAD github.com" -- npm install
4643
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.` ,
4861 Options : serpent.OptionSet {
4962 {
5063 Name : "allow" ,
0 commit comments