Skip to content

Commit 1e687be

Browse files
authored
Merge pull request #35 from coder/bcpeinhardt/adjust-cli-for-coder-consumption
Base command
2 parents 70677f2 + 3bbba0b commit 1e687be

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ build-all:
4040
.PHONY: test
4141
test:
4242
@echo "Running tests..."
43-
sudo go test -v -race ./...
43+
go test -v -race ./...
4444
@echo "✓ All tests passed!"
4545

4646
# Run tests with coverage (needs sudo for E2E tests)
4747
.PHONY: test-coverage
4848
test-coverage:
4949
@echo "Running tests with coverage..."
50-
sudo go test -v -race -coverprofile=coverage.out ./...
50+
go test -v -race -coverprofile=coverage.out ./...
5151
go tool cover -html=coverage.out -o coverage.html
5252
@echo "✓ Coverage report generated: coverage.html"
5353

cli/cli.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,36 @@ type Config struct {
2828

2929
// NewCommand creates and returns the root serpent command
3030
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:
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

Comments
 (0)