/** Author: Mark George <mark.george@otago.ac.nz> License: Zero-Clause BSD License */ package main import ( "fmt" "os" "github.com/jessevdk/go-flags" ) const version string = "2.2" type VersionCommand struct{} func (c *VersionCommand) Execute(args []string) error { fmt.Println("httpcat v" + version) return nil } func main() { parser := flags.NewParser(globalOptions, flags.Default) parser.AddCommand("client", "Send an HTTP request", "", &ClientCommand{}) parser.AddCommand("server", "Start a mock HTTP server", "", &ServerCommand{}) parser.AddCommand("proxy", "Start a reverse HTTP logging proxy", "", &ProxyCommand{}) parser.AddCommand("version", "Display version", "", &VersionCommand{}) _, err := parser.Parse() if err != nil { parseErr := err.(*flags.Error) if parseErr.Type.String() == flags.ErrCommandRequired.String() { os.Stderr.WriteString("\n") parser.WriteHelp(os.Stderr) } } }