Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: parsing args and help info #15

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions internal/config/live-pprof-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ func ParseLPFlags() *LivePprofConfig {
flag.StringVar(&config.Host, "host", "0.0.0.0", "host to listen on")
flag.BoolVarP(&help, "help", "h", false, "help")

flag.BoolVarP(&config.OpenBrowser, "open-browser", "o", true, "open browser on startup")
flag.BoolVarP(&config.OpenBrowser, "no-browser", "n", false, "don't open browser")

flag.Parse()

args := flag.Args()
if len(args) > 0 {
if len(args) == 1 {
config.PprofURL = args[0]
} else if len(args) > 1 {
_, _ = fmt.Fprintf(os.Stderr, "Expected 0 or 1 arg, but %d were given: %v\n", len(args), args)
config.printHelp()
os.Exit(0)
}

if help {
Expand All @@ -47,10 +51,23 @@ func (config *LivePprofConfig) printHelp() {
fmt.Println()
fmt.Println("Usage Example:")
fmt.Println(" live-pprof")
fmt.Println(" open the browser and wait for instructions")
fmt.Println()
fmt.Println(" live-pprof 8080")
fmt.Println(" open the browser and start to monitor http://localhost:8080/debug/pprof")
fmt.Println(" equivalent to `live-pprof http://localhost:8080/debug/pprof`")
fmt.Println(" live-pprof localhost:8080")
fmt.Println(" open the browser and start to monitor http://localhost:8080")
fmt.Println(" live-pprof http://localhost:8080")
fmt.Println(" live-pprof http://localhost:8080/debug/pprof")
fmt.Println(" open the browser and start to monitor http://localhost:8080")
fmt.Println(" live-pprof https://example.com/perf")
fmt.Println(" open the browser and start to monitor https://example.com/perf")
fmt.Println()
fmt.Println(" live-pprof -n")
fmt.Println(" don't open the browser")
fmt.Println(" live-pprof --host 192.168.0.200 -port 1800")
fmt.Println(" listen on 192.168.0.200:1800")
fmt.Println()
fmt.Println("Help")
flag.PrintDefaults()
}